欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

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

程序员文章站 2022-03-28 18:13:51
今天配置之前项目的时候,发现有些动态链接库变了,想看看现在应用在使用哪些动态链接库的时候,进一步查了点资料; 下面针对linux动态链接库查找方法和动态链接库位置配置的过程进行记录: LIBRARY_PATH 和 LD_LIBRARY_PATH 的区别: (参考链接) LIBRARY_PATH is ......

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

下面针对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;

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

/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

保持更新;