Pages

Saturday, 14 November 2015

Linux下,编译/运行软件时的几个重要的变量参数

C头文件调用路径:
1
2
3
export C_INCLUDE_PATH=/usr/local/include:$C_INCLUDE_PATH
#也可在gcc参数中指定调用路径
-I/usr/local/include 
C++头文件调用路径:
1
export CPLUS_INCLUDE_PATH=/usr/local/include:$CPLUS_INCLUDE_PATH
动态库调用路径:
1
2
3
4
5
export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
#也可在gcc参数中指定调用路径
-L/usr/local/lib 
#指定调用库的名字,如libcurl.so
-lcurl
pkg-config路径:
1
export PKG_CONFIG_PATH=/usr/local/pkgconfig/
程序运行时动态库调用路径:
1
2
3
4
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
#也可添加到全局动态库
echo '/usr/local/lib' > /etc/ld.so.conf.d/local.conf
ldconfig
查看gcc默认查找头文件/动态库目录:
1
2
`gcc -print-prog-name=cc1` -v
gcc -print-search-dirs
参考:http://www.cnblogs.com/vamei/archive/2013/04/04/2998850.html