Chinaunix首页 | 论坛 | 博客
  • 博客访问: 534620
  • 博文数量: 95
  • 博客积分: 1415
  • 博客等级: 上尉
  • 技术积分: 1202
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-20 01:23
文章分类

全部博文(95)

文章存档

2010年(28)

2009年(67)

我的朋友

分类: LINUX

2010-08-08 13:28:20

gcc include路径

 

《GCC:the complete referrence》说,gcc的include有以下几个组成:

On a UNIX system, the standard set of system directories is as follows:
/usr/local/include
/usr/lib/gcc-lib/target/version/include
/usr/target/include
/usr/include

通过 gcc -v   *.c 可以看编译时具体过程:
[hyang0@pek-wb-auto ~]$ gcc -v hello.c
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)
/usr/libexec/gcc/i386-redhat-linux/4.1.1/cc1 -quiet -v hello.c -quiet -dumpbase hello.c -mtune=generic -auxbase hello -version -o /tmp/ccPUf6Jg.s
ignoring nonexistent directory "/usr/lib/gcc/i386-redhat-linux/4.1.1/http://www.cnblogs.com/http://www.cnblogs.com/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/i386-redhat-linux/4.1.1/include
/usr/include
End of search list.

GNU C version 4.1.1 20070105 (Red Hat 4.1.1-52) (i386-redhat-linux)
compiled by GNU C version 4.1.1 20070105 (Red Hat 4.1.1-52).
GGC heuristics: --param ggc-min-expand=98 --param ggc-min-heapsize=129176
Compiler executable checksum: 92efef273c2911dfe2bff20f05a618b3
as -V -Qy -o /tmp/ccEed4Cr.o /tmp/ccPUf6Jg.s
GNU assembler version 2.17.50.0.6-2.el5 (i386-redhat-linux) using BFD version 2.17.50.0.6-2.el5 20061020
/usr/libexec/gcc/i386-redhat-linux/4.1.1/collect2 --eh-frame-hdr -m elf_i386 --hash-style=gnu -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc/i386-redhat-linux/4.1.1/http://www.cnblogs.com/../crt1.o /usr/lib/gcc/i386-redhat-linux/4.1.1/http://www.cnblogs.com/../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.1/crtbegin.o -L/usr/lib/gcc/i386-redhat-linux/4.1.1 -L/usr/lib/gcc/i386-redhat-linux/4.1.1 -L/usr/lib/gcc/i386-redhat-linux/4.1.1/http://www.cnblogs.com/.. /tmp/ccEed4Cr.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/i386-redhat-linux/4.1.1/crtend.o /usr/lib/gcc/i386-redhat-linux/4.1.1/http://www.cnblogs.com/../crtn.o
[hyang0@pek-wb-auto ~]$

可以看到search过程:
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc/i386-redhat-linux/4.1.1/include
/usr/include
End of search list.

如果要添加查找路径:
The following is a list of the environment variables that can be set to pass instructions
to the preprocessor.

C_INCLUDE_PATH, CPATH, CPLUS_INCLUDE_PATH, DEPENDENCIES_OUTPUT,
OBJC_INCLUDE_PATH, SUNPRO_DEPENDENCIES

对所有用户有效在/etc/profile增加以下内容。只对当前用户有效在Home目录下的
.bashrc或.bash_profile里增加下面的内容:
(注意:等号前面不要加空格,否则可能出现 command not found)

#在PATH中找到可执行文件程序的路径。
export PATH =$PATH:$HOME/bin

#gcc找到头文件的路径
C_INCLUDE_PATH=/usr/include/libxml2:/MyLib
export C_INCLUDE_PATH

#g++找到头文件的路径
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/include/libxml2:/MyLib
export CPLUS_INCLUDE_PATH

#找到动态链接库的路径
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/MyLib
export LD_LIBRARY_PATH

#找到静态库的路径
LIBRARY_PATH=$LIBRARY_PATH:/MyLib
export LIBRARY_PATH

阅读(7629) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~