尽管设置了 rpath,但没有找到一个 dll
Posted
技术标签:
【中文标题】尽管设置了 rpath,但没有找到一个 dll【英文标题】:Despite rpath is set, one dll is not found 【发布时间】:2018-03-23 08:41:45 【问题描述】: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 => 未找到 librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f31a9fc4000) [...]
root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# 文件 ../lib/libexpat.so.0 ../lib/libexpat.so.0:ELF 64 位 LSB 共享 对象,x86-64,版本 1 (SYSV),动态链接, BuildID[sha1]=762de704943d03033d01a9725216d6b05d0740f5,未剥离
这里是rpath:
root@hyperstream:/DT/local/ADE-trunk4/build-ADE-Desktop-Default/bin# readelf -d ade_admin | grep 'R.*PATH' 16: 0x000000000000001d (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# 导出 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)
有什么想法吗?
问候
劳伦特
【问题讨论】:
您知道,“DLL”是共享库的Windows 特定 名称。在 Linux/Unix 领域,我们只称它们为“共享库”或“SOs”(发音为“ess ohs”)。在同一个句子中看到“RPATH”和“DLL”很奇怪,因为 Windows 没有等效的 RPATH。 【参考方案1】:我只是找到了解释:clang 放入了 elf 二进制 ALL 库的 [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/]
来自铿锵声:
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
希望对你有帮助
【讨论】:
以上是关于尽管设置了 rpath,但没有找到一个 dll的主要内容,如果未能解决你的问题,请参考以下文章
尽管下载了ffmpeg并设置了路径变量python,但没有后端错误