首页 > 系统服务 > 详细

【Linux笔记】linux系统下链接可执行文件时,linker如何查找共享库

时间:2014-12-24 16:16:05      阅读:290      评论:0      收藏:0      [点我收藏+]
当要编译的可执行程序依赖共享库时,linker按下面所示顺序查找其依赖的库。
下面的内容出自gcc manual,作为笔记,记录于此。

The linker uses the following search paths to locate required shared libraries.

 1. Any directories specified by -rpath-link options.

 2. Any directories specified by -rpath options. The difference between -rpath and -rpath-link is that directories specified by -rpath options are included in the executable and used at runtime, whereas the -rpath-link option is only effective at link time. It is for the native linker only.

 3. On an ELF system, if the -rpath and "rpath-link" options were not used, search the contents of the environment variable "LD_RUN_PATH". It is for the native linker only.

 4. On SunOS, if the -rpath option was not used, search any directories specified using -L options.

 5. For a native linker, the contents of the environment variable "LD_LIBRARY_PATH".

 6. For a native ELF linker, the directories in "DT_RUNPATH" or "DT_RPATH" of a shared library are searched for shared libraries needed by it. The "DT_RPATH" entries are ignored if "DT_RUNPATH" entries exist.

 7. The default directories, normally /lib and /usr/lib.

 8. For a native linker on an ELF system, if the file /etc/ld.so.conf exists, the list of directories found in that file.

If the required shared library is not found, the linker will issue a warning and continue with the link.

可见,-rpath-link指定的查找路径只会被linker使用,而-rpath指定的查找路径除用于linker查找外,还会在进程启动时被loader作为共享库查找路径。

【参考资料】
1. -rpath in manual page of gcc: man gcc and find -rpath

======================= EOF ====================


【Linux笔记】linux系统下链接可执行文件时,linker如何查找共享库

原文:http://blog.csdn.net/slvher/article/details/42124965

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!