在Unix系统中,gcc在哪里查找头文件?
今天早上我花了一点时间寻找一些系统头文件,所以我认为这将是很好的信息。
在Unix系统中,gcc在哪里查找头文件?
今天早上我花了一点时间寻找一些系统头文件,所以我认为这将是很好的信息。
当前回答
你可以通过查看以下命令查看bash中C程序的(额外的)include路径:
echo $C_INCLUDE_PATH
如果这是空的,它可以被修改为添加默认的包含位置,通过:
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/include
其他回答
g++ -print-search-dirs
gcc -print-search-dirs
GCC手册的CPP章节指出头文件可能位于以下目录中。从搜索路径页面:
GCC在几个不同的地方寻找头文件。在一个普通的Unix系统中,如果你没有指示它,它将在#include中查找请求的头文件:
/usr/local/include
libdir/gcc/target/version/include
/usr/target/include
/usr/include
对于c++程序,它也会首先查找/usr/include/g++-v3。
编译器查找头文件的路径集可以通过以下命令检查:-
CPP -V
如果声明#include "",编译器首先在源文件的当前目录中搜索,如果没有找到,则继续在上述检索到的目录中搜索。
如果声明#include <>,编译器将直接在从上述命令获得的目录中搜索。
来源:http://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art026
此外,gcc将查找在-I选项后指定的目录。
这些是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.