Linux下获取binary中的rpath信息,rpath的意义

objdump -x binary-or-library | grep RPATH

或者

readelf -d binary-or-library | head -20

windows 下一个程序的dll搜索路径首先是程序目录,然后是一些系统目录。linux 下的可以通过设置 LD_LIBRARY_PATH 等方法来添加搜索路径,但是这些路径是定死的,如果要实现程序目录,就要使用链接时的rpath选项。rpath 适用于 elf 文件,不适用 pe。
 

Linux 上动态库搜索顺序:

Unless loading object has RUNPATH:
    RPATH of the loading object,
        then the RPATH of its loader (unless it has a RUNPATH), ...,
        until the end of the chain, which is either the executable
        or an object loaded by dlopen(loader 为可执行程序或被 dlopen 打开的对象)
    Unless executable has RUNPATH:
        RPATH of the executable
LD_LIBRARY_PATH
RUNPATH of the loading object
ld.so.cache
default dirs

转载于:https://my.oschina.net/lieefu/blog/756091