我尝试使用patchelf更改python的RPATH以指向本地安装的新更新库。但是python仍然无法找到新的库。
相反,如果我设置LD_LIBRARY_PATH环境变量,那么python工作正常。
我正在做以下事情
patchelf --set-rpath /home/user/new_lblas/ /home/user/.local/python
new_lblas
指向更新的软件包,如intel-lapack,blas等。
如果我现在python -c 'import numpy'
,则会发现libblas.so.3gf
没有找到。
但是,如果我设置环境变量LD_LIBRARY_PATH=/home/user/new_lblas
,那么python中的import numpy
可以正常工作。
有人可以帮助弄清楚我在做什么错误吗?
执行patchelf后readelf -d /home/user/.local/python
的输出如下所示
Dynamic section at offset 0x270 contains 26 entries:
Tag Type Name/Value
0x000000000000001d (RUNPATH) Library runpath: [/home/user/new_lblas]
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libutil.so.1]
0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x41b700
0x000000000000000d (FINI) 0x569238
0x000000006ffffef5 (GNU_HASH) 0x4146b0
0x0000000000000005 (STRTAB) 0x3ff460
0x0000000000000006 (SYMTAB) 0x4085c0
0x000000000000000a (STRSZ) 37214 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000015 (DEBUG) 0x0
0x0000000000000003 (PLTGOT) 0x7f9fe8
0x0000000000000002 (PLTRELSZ) 8040 (bytes)
在做patchelf之前,ELF标题如下所示
Dynamic section at offset 0x1f9e00 contains 25 entries:
Tag Type Name/Value
0x0000000000000001 (NEEDED) Shared library: [libpthread.so.0]
0x0000000000000001 (NEEDED) Shared library: [libdl.so.2]
0x0000000000000001 (NEEDED) Shared library: [libutil.so.1]
0x0000000000000001 (NEEDED) Shared library: [librt.so.1]
0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
0x000000000000000c (INIT) 0x41b700
0x000000000000000d (FINI) 0x569238
0x000000006ffffef5 (GNU_HASH) 0x400298
0x0000000000000005 (STRTAB) 0x40f6a8
0x0000000000000006 (SYMTAB) 0x4035b8
0x000000000000000a (STRSZ) 36637 (bytes)
0x000000000000000b (SYMENT) 24 (bytes)
0x0000000000000015 (DEBUG) 0x0
0x0000000000000003 (PLTGOT) 0x7f9fe8
0x0000000000000002 (PLTRELSZ) 8040 (bytes)
0x0000000000000014 (PLTREL) RELA
答案 0 :(得分:2)
至少有3种方法可以设置动态链接器搜索路径:
export LD_LIBRARY_PATH=/home/user/new_lblas
DT_RPATH
/home/user/new_lblas
动态代码
DT_RUNPATH
的{{1}}动态代码。上面的#1和#2是等价的,但是#3(你正在做的事情)不是。区别很小:/home/user/new_lblas
影响二进制和所有共享库,但RPATH
仅影响 二进制文件,不影响 / em>递归地应用于此二进制文件加载的共享库。
这解释了为什么RUNPATH
有效,但LD_LIBRARY_PATH
没有。
看看patchelf man page,您似乎想要:
RUNPATH