C_INCLUDE_PATH,LIBRARY_PATH,LD_LIBRARY_PATH(转)

来源:互联网 发布:windows bat脚本 cd 编辑:程序博客网 时间:2024/05/17 04:11

利用系统的环境变量。
对于头文件的搜索路径:

C_INCLUDE_PATH=<your include path>;
export C_INCLUDE_PATH

对于库文件的搜索路径:

LIBRARY_PATH=<your lib path>;
export LIBRARY_PATH

对于链接程序ld使用的库文件搜索路径:

LD_LIBRARY_PATH=<your ldlib path>;
export LD_LIBRARY_PATH


LIBRARY_PATH is used by gcc before compilation to search for directories containing libraries that need to be linked to your program.

LD_LIBRARY_PATH is used by your program to search for directories containing the libraries after it has been successfully compiled and linked.

EDIT:As pointed below, your libraries can be static or shared. If it is static then the code is copied over into your program and you don't need to search for the library after your program is compiled and linked. If your library is shared then it needs to be dynamically linked to your program and that's when LD_LIBRARY_PATH comes into play.