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

Despite rpath is set, one dll is not found

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

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

root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# ldd ./ade_admin linux-vdso.so.1 => (0x00007ffeb9796000) libadeversion.so => /DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin/./../lib/libadeversion.so (0x00007f31abaef000) libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f31ab8ca000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f31ab6ac000) libaprutil-1.so.0 => /DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin/./../lib/libaprutil-1.so.0 (0x00007f31ab58c000) libapr-1.so.0 => /DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin/./../lib/libapr-1.so.0 (0x00007f31ab460000) libavahi-client.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-client.so.3 (0x00007f31ab24d000) libavahi-common.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-common.so.3 (0x00007f31ab041000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f31aae3d000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f31aaab5000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f31aa7ac000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f31aa595000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f31aa1cc000) /lib64/ld-linux-x86-64.so.2 (0x0000560d30a76000) libexpat.so.0 => not found librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f31a9fc4000) [...]

root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# file ../lib/libexpat.so.0 ../lib/libexpat.so.0: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=762de704943d03033d01a9725216d6b05d0740f5, not stripped

这里是 rpath:

root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# readelf -d ade_admin | grep 'R.*PATH' 16: 0x000000000000001d (RUNPATH) Library runpath: [${ORIGIN}/../lib]

现在致命的事实:它适用于 clang 3.8,但不适用于 gcc 6.3 (ubuntu 16.10)

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

root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# export LD_LIBRARY_PATH=../lib root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# ldd ./ade_admin linux-vdso.so.1 => (0x00007ffea23b6000) libadeversion.so => ../lib/libadeversion.so (0x00007f78c6474000) libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f78c624f000) libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f78c6031000) libaprutil-1.so.0 => ../lib/libaprutil-1.so.0 (0x00007f78c5f11000) libapr-1.so.0 => ../lib/libapr-1.so.0 (0x00007f78c5de5000) libavahi-client.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-client.so.3 (0x00007f78c5bd2000) libavahi-common.so.3 => /usr/lib/x86_64-linux-gnu/libavahi-common.so.3 (0x00007f78c59c6000) libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f78c57c2000) libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f78c543a000) libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f78c5131000) libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f78c4f1a000) libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f78c4b51000) /lib64/ld-linux-x86-64.so.2 (0x0000559fdceab000) libexpat.so.0 => ../lib/libexpat.so.0 (0x00007f78c492a000)

有什么想法吗?

此致

洛朗

我只是找到了解释: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 以强制包含来自“.”的库 - 在我的构建中明确添加所有缺失的 dll

希望对您有所帮助