给定一个可执行文件,使得:有没有办法在链接时设置elf NEEDED字段?
>objdump -x someprog | grep c++
NEEDED libstdc++.so.6
我想换到完整版本的要求(包括次要版本和补丁级别):
>objdump -x someprog | grep c++
NEEDED libstdc++.so.6.0.22
我知道有两种方法可以做到这:
- 创建一个虚拟库按这个问题(Forcing or preventing use of a particular minor version of libstdc++)
- 使用PATC HELF
>patchelf --add-needed libstdc++.so.6.0.22 someprog >objdump -x someprog | grep c++ NEEDED libstdc++.so.6 NEEDED libstdc++.so.6.0.22
(我还没有想出了--replace需要的工作命令行)
的这些感觉像黑客给我两个。 有没有办法在编译或链接时使用相应的-Wl标志来实现gcc?
理想情况下,我想避免使用-nostdlib,因为这需要我具体不只是libstd ++,但libc和其他所有我想要的标准版本。
对于只连接到特定版本的常规库就足够用于libstdC++,它不是(或者说我怀疑-stdlib覆盖了我提供的后续完全限定名称)。
背景:我的可执行文件需要安装在系统上的更高版本的libstdc++
。不幸的是,安装的版本可能是相同的主要版本,如果是ld
会很乐意使用的系统版本,因为它符合SONAMElibstdc++.so.6
我不喜欢静态链接,因为我真的想安装许多小程序共享同一C++运行时间,这会大大增加安装量。
对我(的)库搜索路径的一些信息,请访问:
LD --verbose | grep SEARCH_DIR SEARCH_DIR(“/ usr/x86_64-redhat-linux/lib64”); SEARCH_DIR( “/ USR/lib64下”); SEARCH_DIR( “/ USR /本地/ lib64下”); SEARCH_DIR( “/ lib64下”); SEARCH_DIR( “/ USR/x86_64的-红帽-LINUX/LIB”); SEARCH_DIR( “/ USR/local/lib目录”); SEARCH_DIR( “/ LIB”); SEARCH_DIR( “/ usr/lib中”);
这是在我的情况清楚地表明在/ usr /正在搜索lib64的前可执行的RPATH是:
>objdump -x /opt/emma/bin/stm2emma | grep PATH
RPATH $ORIGIN/../lib64/private:$ORIGIN/../lib64:$ORIGIN/
man ld.so
表明搜索顺序应该是:
如果库依赖项不包含斜杠,则按以下顺序搜索 :
o (ELF only) Using the directories specified in the DT_RPATH dynamic section attribute of the binary if present and DT_RUNPATH attribute does not exist. Use of DT_RPATH is deprecated.
o Using the environment variable LD_LIBRARY_PATH. Except if the executable is a set-user-ID/set-group-ID binary, in which case it is ignored.
o (ELF only) Using the directories specified in the DT_RUNPATH dynamic section attribute of the binary if present.
o From the cache file /etc/ld.so.cache, which contains a compiled list of candidate libraries previously found in the augmented library path. If, however, the binary was linked with the -z node‐
flib linker option, libraries in the default library paths are skipped. Libraries installed in hardware capability directories (see below) are preferred to other libraries.
o In the default path /lib, and then /usr/lib. If the binary was linked with the -z nodeflib linker option, this step is skipped.
同样https://software.intel.com/sites/default/files/m/a/1/e/dsohowto.pdf
似乎都被实际使用,但实际上被捏造事实并非如此。 需要的是寻找符号链接:
>LD_LIBRARY_PATH= LD_DEBUG=libs ldd /opt/foo/bin/bar
21720: find library=libstdc++.so.6 [0]; searching
21720: search path=/opt/foo/bin/../lib64/private:/opt/foo/bin/../lib64:/opt/foo/bin (RPATH from file /opt/foo/bin/bar)
21720: trying file=/opt/foo/bin/../lib64/private/libstdc++.so.6
这是与另外一个问题我不得不install shared imported library with necessary links其中建议是,不需要链接的交互。 如果你没有指定完整的语义版本,他们显然是。
之前/之后的情况似乎没有区别,所以目前还不清楚你想要什么。 –
这是我的错误(现在已修复),我的意思是如此.6.0.22。不是这样。0 –
现在它再次有意义,希望downvotes将被删除。 –