尽管设置了rpath,但找不到一个dll

时间:2017-10-11 15:28:47

标签: linux gcc clang ldd rpath

ldd无法找到rpath定义中存在的dll。找到其他一些库(检查/./../ lib / *)

这里是ldd的输出(我们可以看到在./lib中找到了2个dll,但没有找到libexpat.so.0:

  

根@ hyperstream:/ DT /本地/ ADE-trunk4 /集结ADE-桌面 - 缺省/仓#   ldd ./ade_admin linux-vdso.so.1 =&gt; (0x00007ffeb9796000)     libadeversion.so =&gt;   /DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin/./../lib/libadeversion.so   (0x00007f31abaef000)libuuid.so.1 =&gt;   /lib/x86_64-linux-gnu/libuuid.so.1(0x00007f31ab8ca000)     libpthread.so.0 =&gt; /lib/x86_64-linux-gnu/libpthread.so.0   (0x00007f31ab6ac000)libaprutil-1.so.0 =&gt;   / DT /本地/ ADE-trunk4 /集结ADE-桌面 - 缺省/ bin中/的 ./../ LIB / libaprutil-1.so.0   (0x00007f31ab58c000)libapr-1.so.0 =&gt;   / DT /本地/ ADE-trunk4 /集结ADE-桌面 - 缺省/ bin中/的 ./../ LIB / APR的-1.so.0   (0x00007f31ab460000)libavahi-client.so.3 =&gt;   /usr/lib/x86_64-linux-gnu/libavahi-client.so.3(0x00007f31ab24d000)     libavahi-common.so.3 =&gt;   /usr/lib/x86_64-linux-gnu/libavahi-common.so.3(0x00007f31ab041000)     libdl.so.2 =&gt; /lib/x86_64-linux-gnu/libdl.so.2(0x00007f31aae3d000)     libstdc ++。so.6 =&gt; /usr/lib/x86_64-linux-gnu/libstdc++.so.6   (0x00007f31aaab5000)libm.so.6 =&gt; /lib/x86_64-linux-gnu/libm.so.6   (0x00007f31aa7ac000)libgcc_s.so.1 =&gt;   /lib/x86_64-linux-gnu/libgcc_s.so.1(0x00007f31aa595000)libc.so.6 =&gt;   /lib/x86_64-linux-gnu/libc.so.6(0x00007f31aa1cc000)     /lib64/ld-linux-x86-64.so.2(0x0000560d30a76000)< strong> libexpat.so.0 =&gt;   找不到 librt.so.1 =&gt; /lib/x86_64-linux-gnu/librt.so.1   (0x00007f31a9fc4000)[...]

     

根@ hyperstream:/ DT /本地/ ADE-trunk4 /集结ADE-桌面 - 缺省/仓#   file ../lib/libexpat.so.0 ../lib/libexpat.so.0:ELF 64位LSB共享   对象,x86-64,版本1(SYSV),动态链接,   BuildID [sha1] = 762de704943d03033d01a9725216d6b05d0740f5,未剥离

这里是rpath:

  

根@ hyperstream:/ DT /本地/ ADE-trunk4 /集结ADE-桌面 - 缺省/仓#   readelf -d ade_admin | grep&#39; R. * PATH&#39; 16:0x000000000000001d(RUNPATH)   库运行路径: [$ {ORIGIN} /../ lib]

现在的杀手锏:它与clang 3.8一起使用,但在gcc 6.3(ubuntu 16.10)中失败

显然添加LD_LIBRARY_PATH = .. / lib使其再次起作用,但rpath的目标是避免设置它

  

根@ hyperstream:/ DT /本地/ ADE-trunk4 /集结ADE-桌面 - 缺省/仓#   export LD_LIBRARY_PATH = .. / lib   根@ hyperstream:/ DT /本地/ ADE-trunk4 /集结ADE-桌面,默认/ bin中#   ldd ./ade_admin linux-vdso.so.1 =&gt; (0x00007ffea23b6000)     libadeversion.so =&gt; ../lib/libadeversion.so(0x00007f78c6474000)     libuuid.so.1 =&gt; /lib/x86_64-linux-gnu/libuuid.so.1   (0x00007f78c624f000)libpthread.so.0 =&gt;   /lib/x86_64-linux-gnu/libpthread.so.0(0x00007f78c6031000)     libaprutil-1.so.0 =&gt; ../lib/libaprutil-1.so.0(0x00007f78c5f11000)     libapr-1.so.0 =&gt; ../lib/libapr-1.so.0(0x00007f78c5de5000)     libavahi-client.so.3 =&gt;   /usr/lib/x86_64-linux-gnu/libavahi-client.so.3(0x00007f78c5bd2000)     libavahi-common.so.3 =&gt;   /usr/lib/x86_64-linux-gnu/libavahi-common.so.3(0x00007f78c59c6000)     libdl.so.2 =&gt; /lib/x86_64-linux-gnu/libdl.so.2(0x00007f78c57c2000)     libstdc ++。so.6 =&gt; /usr/lib/x86_64-linux-gnu/libstdc++.so.6   (0x00007f78c543a000)libm.so.6 =&gt; /lib/x86_64-linux-gnu/libm.so.6   (0x00007f78c5131000)libgcc_s.so.1 =&gt;   /lib/x86_64-linux-gnu/libgcc_s.so.1(0x00007f78c4f1a000)libc.so.6 =&gt;   /lib/x86_64-linux-gnu/libc.so.6(0x00007f78c4b51000)     /lib64/ld-linux-x86-64.so.2(0x0000559fdceab000)libexpat.so.0 =&gt;   。 ./ lib / libexpat.so.0 (0x00007f78c492a000)

有什么想法吗?

此致

劳伦

1 个答案:

答案 0 :(得分:1)

我只是找到了解释:clang放入了elf二进制文件库的[NEEDED]部分(甚至我自己没有明确包含的库,但是我所包含的库的[NEEDED]部分引用了

来自gcc的例子:

readelf -d my_prog

Dynamic section at offset 0x9cb548 contains 46 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libadeversion.so]
 0x0000000000000001 (NEEDED)             Shared library: [libuuid.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libsqlite3.so]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libaprutil-1.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libapr-1.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libavahi-client.so.3]
 0x0000000000000001 (NEEDED)             Shared library: [libavahi-common.so.3]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libaio.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [lib_adm64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_dict64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_rdm64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_dbr64.so]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [${ORIGIN}/../lib/:$ORIGIN/../lib/:../lib/]

来自clang:

readelf -d my_prog

Dynamic section at offset 0xa7bae8 contains 54 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libadeversion.so]
 0x0000000000000001 (NEEDED)             Shared library: [libuuid.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libsqlite3.so]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libaprutil-1.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libexpat.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libapr-1.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libavahi-client.so.3]
 0x0000000000000001 (NEEDED)             Shared library: [libavahi-common.so.3]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libaio.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libcrypt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [lib_adm64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_dict64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_rdm64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_rpc64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_sql64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_rdbc64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_rm64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_ncp64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_cmp64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_repfltr64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_expat64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_cncp64.so]
 0x0000000000000001 (NEEDED)             Shared library: [lib_dbr64.so]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [${ORIGIN}/../lib/:$ORIGIN/../lib/:../lib/]

一个dll包含缺少的一个libexpat:

readelf -d ../lib/libaprutil-1.so.0 

Dynamic section at offset 0x1e698 contains 29 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: **[libexpat.so.0]**
 0x0000000000000001 (NEEDED)             Shared library: [libapr-1.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libuuid.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libcrypt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000000e (SONAME)             Library soname: [libaprutil-1.so.0]

但RUNPATH仅由二进制文件使用,而不是由dll使用(也可以是自己的RUNPATH)。

2个解决方案: - 在libaprutil-1.so.0中添加一个RUNPATH以强制包含来自&#34;。&#34;的库。 - 在我的构建中明确添加所有缺少的dll

希望有所帮助