开发者

Including C header files from other directory

开发者 https://www.devze.com 2023-01-24 15:47 出处:网络
My understanding was always that by doing #include <header.h> it looks in the system include directories, and that #include \"header.h\" it looks in the local directory. But I was just looking a

My understanding was always that by doing #include <header.h> it looks in the system include directories, and that #include "header.h" it looks in the local directory. But I was just looking at the python source code and it uses the "header.h" method to define headers in a sibling directory.

So in py3k/Python/ast.c it does #include "Pyt开发者_运维问答hon.h". But Python.h is in py3k/Include/Python.h

Is this something common that I've just never seen, not having worked on any real large C project? How do I tell, at least my IDE, to look in py3k/Include?

Update

I figured out how to tell my IDE to include them, it was just me being stupid and a spelling error. But I'm more interested in why "" works. Is that not the different between "" and <>?


Both #include <header> and #include "header" look in "implementation-defined places", i.e. it depends on the compiler you are using and its settings. For #include <h> it's usually some standard system include directories and whatever you configure the compiler to look in additionally.
The difference between the two versions is that if the search for #include "header" is not supported or fails, it will be reprocessed "as if it read #include <header>" (C99, §6.10.2).


You need to somehow tell your compiler what directories to search in -- for GCC this means using the -I flag. Look it up for your combination of IDE / compiler.

0

精彩评论

暂无评论...
验证码 换一张
取 消