linux 动态链接库查找方法;查找动态链接库位置; LIBRARY_PATH 和 LD_LIBRARY_PATH 的区别;LD_LIBRARY_PATH and LD_RUN_PATH的区别;

今天配置之前项目的时候,发现有些动态链接库变了,想看看现在应用在使用哪些动态链接库的时候,进一步查了点资料;

下面针对linux动态链接库查找方法和动态链接库位置配置的过程进行记录:

LIBRARY_PATH 和 LD_LIBRARY_PATH 的区别: (参考链接)

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

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

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_LIBRARY_PATH and LD_RUN_PATH 的区别: (参考链接)

LD_RUN_PATH is used for the link time resolution of libraries whilst LD_LIBRARY_PATH is used for run time resolution of libraries. LD_RUN_PATH Specifies the directories that are to be searched for libraries at both link and run time.

LD_LIBRARY_PATH indicates to the dynamic loader to search the colon delimited paths for libraries required to execute the binary.  LD_RUN_PATH is used by the linker to specify where to look for libraries only at run time.  This differs ever so slightly from LD_LIBRARY_PATH in that this set of paths are not searched during link time.

动态链接库查找路径配置:

1. 可以使用上面 LD_LIBRARY_PATH 等环境变量进行配置

2. 可以使用 /etc/ld.so.conf 全局配置文件,配置动态链接库运行时的搜索路径; 然后使用ldconfig命令,进行将/etc/ld.so.conf加载到ld.so.cache之中(需要root权限);

3. 然后使用:ldconfig -p | grep "your lib" 进行查找所需要动态链接库的位置;

4. 针对已有程序,可以使用 ldd "your bin" 进行直接看当前执行程序所需要的链接库的情况;

保持更新,转载请注明出处;更多内容,请关注 cnblogs.com/xuyaowen;

/etc/ld.so.conf.d/x86_64-linux-gnu.conf,多体系结构支持配置,以x86_64为例:

# Multiarch support
/usr/local/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu

保持更新;

posted @ 2019-12-06 14:01  xuyaowen  阅读(...)  评论(...编辑  收藏