gcc/g++搜索路径

一:查看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’

三:动态库的搜索路径搜索的先后顺序是:

1 编译目标代码时指定的动态库搜索路径;

2 环境变量LD_LIBRARY_PATH指定的动态库搜索路径;

3 配置文件/etc/ld.so.conf中指定的动态库搜索路径;

4 默认的动态库搜索路径/lib;

5 默认的动态库搜索路径/usr/lib。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值