我安装了一个非系统的g++,并试图用
/MYINSTALLDIR/g++ -L/MYINSTALLLIBDIR -Wl,-rpath,MYINSTALLLIBDIR main.cpp -o tester但是当我跑的时候
ldd ./试验器
我了解到,libstdc++和其他链接gcc/g++库是系统安装,而不是那些指定的rpath位置。
我已经阅读了linking g++ 4.8 to libstdc++,而我看到的唯一尝试的选项是更改g++规范文件。因为它是由root拥有的,这对我来说是个问题。
有什么建议吗?
(注意,我也查过LD_LIBRARY_PATH=了。我宁愿不改变LD_LIBRARY_PATH。)
编辑:我试着查看二进制文件中所需的和RPATH字段,它们正是我所期望的。例如,所需包含"libstdc++“,RPATH只是MYINSTALLLIBDIR的值。
然后我设置了LD_DEBUG="libs“,并在测试器上重新运行ldd。看起来ldd在系统版本之前看到了正确的库路径,但没有选择它。与libstdc++相关的输出如下:
13337: find library=libstdc++.so.6 [0]; searching
13337: search path=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/tls/x86_64:/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/tls:/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/x86_64:/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2 (RPATH from file ./tester)
13337: trying file=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/tls/x86_64/libstdc++.so.6
13337: trying file=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/tls/libstdc++.so.6
13337: trying file=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/x86_64/libstdc++.so.6
13337: trying file=/opt/rh/devtoolset-2/root/usr/lib/gcc/x86_64-redhat-linux/4.8.2/libstdc++.so.6
13336: 13337: find library=libc.so.6 search cache= [/etc/ld.so.cache0]; searching
13336: search cache=/etc/ld.so.cache
13337: trying file=/usr/lib64/libstdc++.so.6
13336: 13337: trying file=我认为正确的libstdc++应该是/opt/rh/./4.8.2文件夹中的"libstdc++.so“。那里没有"libstdc++.so.6“。
编辑: Marc是正确的。原来新gcc libstdc++.so只是选择了以前安装的系统版本。所以这似乎是正确的行为。
发布于 2019-01-18 14:41:29
您正在使用中的GCC,该工具使用一个特殊的链接模型,以确保它编译的二进制文件不依赖于较新的,而不是,这正是为了使不必在设置RPATH或LD_LIBRARY_PATH之类的问题上搞砸。它只适用于™。因此,看到二进制文件依赖于系统libstdc++.so.6正是应该发生的事情。
在结束这个答案时,我已经重复了另一个类似的答案,其中我已经给出了关于如何使用devtoolset链接到libstdc++的更多细节。
https://stackoverflow.com/questions/23819800
复制相似问题