一:查看gcc/g++默认include路径
`gcc -print-prog-name=cc1plus` -v
`g++ -print-prog-name=cc1plus` -v
echo 'main(){}' | gcc -E -v -
二:include搜索路径
1.当前目录
2.编译的时候指定的路径,比如–prefix=/usr/local,查找的时候去/usr/local/include
3.gcc的specs里,(Command Options),这个不清楚怎么用了。
4.使用-I参数指定的路径,比如g++ demo.cpp -I../include/demo.h ‘这几个路径中-I参数指定的路径优先级最高。 在gcc的手册里是这么说的: omit…
5.gcc环境变量设置
CPATH C_INCLUDE_PATH CPLUS_INCLUDE_PATH OBJC_INCLUDE_PATH
6.系统标准include路径
'GCC looks in several different places for headers. On a normal Unix system, if you do not instruct it otherwise, it will look for headers requested with #include <file> in: /usr/local/include libdir/gcc/target/version/include /usr/target/include /usr/include For C++ programs, it will also look in libdir/../include/c++/version, first. In the above, target is the canonical name of the system GCC was configured to compile code for; often but not always the same as the canonical name of the system it runs on. version is the version of GCC in use.
比如在我的系统上执行
g++ -print-prog-name=cc1plus
-v
可以得到系统的标准路径:
“/usr/lib/gcc/x86_64-redhat-linux/4.8.3/../../../../x86_64-redhat-linux/include” 、
#include “…” search starts here: 、
#include <…> search starts here: .
/usr/lib/gcc/x86_64-redhat-linux/4.8.3/../../../../include/c++/4.8.3
/usr/lib/gcc/x86_64-redhat-linux/4.8.3/../../../../include/c++/4.8.3/x86_64-redhat-linux/usr/lib/gcc/x86_64-redhat-linux/4.8.3/../../../../include/c++/4.8.3/backward
/usr/local/include
End of search list.
可以看到系统的标准include路径:
/usr/local/include
libdir/gcc/target/version/include
/usr/target/include
/usr/include
libdir/../include/c++/version’