我有一个非系统安装的g,我正在尝试使用编译程序
/MYINSTALLDIR/g++ -L/MYINSTALLLIBDIR -Wl,-rpath,MYINSTALLLIBDIR main.cpp -o tester
但是当我跑的时候
ldd ./tester
我知道libstdc和其他链接的gcc / g库是系统安装而不是指定rpath位置的库 .
我已阅读linking g++ 4.8 to libstdc++,我看到的唯一其他选项是更改g spec文件 . 由于它归root所有,这对我来说会有问题 .
有什么建议?
(注意,我已经检查过LD_LIBRARY_PATH =“” . 我宁愿不改变LD_LIBRARY_PATH . )
编辑:我试着查看二进制文件中的NEEDED和RPATH字段,它们是我所期望的 . 例如,NEEDED包含“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=
我相信在/opt/rh/.../4.8.2文件夹中正确的libstdc应该是“libstdc .so” . 那里没有“libstdc .so.6” .
编辑:Marc Glisse是对的 . 事实证明,新的gcc libstdc .so只选择以前安装的系统版本 . 所以这似乎是正确的行为 .