在Unix系统中,gcc在哪里查找头文件?

今天早上我花了一点时间寻找一些系统头文件,所以我认为这将是很好的信息。


当前回答

你可以通过查看以下命令查看bash中C程序的(额外的)include路径:

echo $C_INCLUDE_PATH

如果这是空的,它可以被修改为添加默认的包含位置,通过:

export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/include

其他回答

你可以通过查看以下命令查看bash中C程序的(额外的)include路径:

echo $C_INCLUDE_PATH

如果这是空的,它可以被修改为添加默认的包含位置,通过:

export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/include

编译器查找头文件的路径集可以通过以下命令检查:-

CPP -V

如果声明#include "",编译器首先在源文件的当前目录中搜索,如果没有找到,则继续在上述检索到的目录中搜索。

如果声明#include <>,编译器将直接在从上述命令获得的目录中搜索。

来源:http://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art026

这些是gcc在默认情况下查找指定头文件的目录(假定头文件包含在chevrons <>中); 1. /usr/local/include/——用于第三方头文件。 2. /usr/include/——用于系统头文件。

If in case you decide to put your custom header file in a place other than the above mentioned directories, you can include them as follows: 1. using quotes ("./custom_header_files/foo.h") with files path, instead of chevrons in the include statement. 2. using the -I switch when compiling the code. gcc -I /home/user/custom_headers/ -c foo.c -p foo.o Basically the -I switch tells the compiler to first look in the directory specified with the -I switch ( before it checks the standard directories).When using the -I switch the header files may be included using chevrons.

g++ -print-search-dirs
gcc -print-search-dirs
`gcc -print-prog-name=cc1plus` -v

这个命令会问gcc它正在使用哪个c++预处理器,然后问这个预处理器在哪里查找include。

对于特定的设置,您将得到一个可靠的答案。

同样,对于C预处理器:

`gcc -print-prog-name=cpp` -v