前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux 动态链接库查找方法;查找动态链接库位置; LIBRARY_PATH 和 LD_LIBRARY_PATH 的区别;LD_LIBRARY_PATH and LD_RUN_PATH的区别;MAC

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

作者头像
xuyaowen
发布2020-12-30 14:26:33
1.7K0
发布2020-12-30 14:26:33
举报
文章被收录于专栏:XUYAOWEN的专栏XUYAOWEN的专栏

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

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

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

代码语言:javascript
复制
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 的区别: (参考链接)

代码语言:javascript
复制
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为例:

代码语言:javascript
复制
# Multiarch support
/usr/local/lib/x86_64-linux-gnu
/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu

保持更新;

otool -L pk # macos 使用此方法进行查看;

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-12-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档