利用系统的环境变量。
对于头文件的搜索路径:
C_INCLUDE_PATH=<your include path>;
CPLUS_INCLUDE_PATH=<your include path>
export C_INCLUDE_PATH
export CPLUS_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.
本文介绍了如何通过设置环境变量来指定编译器搜索头文件、库文件及链接程序ld所需的库文件路径。具体包括C_INCLUDE_PATH、CPLUS_INCLUDE_PATH、LIBRARY_PATH和LD_LIBRARY_PATH等变量的作用与用法。
&spm=1001.2101.3001.5002&articleId=8217041&d=1&t=3&u=ba23469fc9ca4e2d8f1d3b11b88862a6)
5692

被折叠的 条评论
为什么被折叠?



