Linker 针对不同glibc的链接

Linker 针对不同glibc的链接,linker,g++,glibc,Linker,G++,Glibc,我已将glibc-2.18安装到我的主目录中,并希望针对它链接应用程序: $ g++ -pthread -o tsx_test tsx_test.cpp -Wl,--rpath=/home/hl/lib/ \ -Wl,--dynamic-linker=/home/hl/lib/ld-linux-x86-64.so.2 使用g++4.7.3编译和链接工作正常,但在执行时失败: $ ./tsx_test ./tsx_test: error while loading shared librar

我已将glibc-2.18安装到我的主目录中,并希望针对它链接应用程序:

$ g++ -pthread -o tsx_test tsx_test.cpp -Wl,--rpath=/home/hl/lib/ \
  -Wl,--dynamic-linker=/home/hl/lib/ld-linux-x86-64.so.2
使用g++4.7.3编译和链接工作正常,但在执行时失败:

$ ./tsx_test
./tsx_test: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory
/usr/lib/x86_64-linux-gnu/libstdc++.so.6肯定存在,当我编译时没有“-rpath”相同的libstdc++.so.6链接,一切正常

$ ldd tsx_test
linux-vdso.so.1 =>  (0x00007fff42bd4000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f42aa3aa000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f42aa194000)
libpthread.so.0 => /home/hl/lib/libpthread.so.0 (0x00007f42a9f75000)
libc.so.6 => /home/hl/lib/libc.so.6 (0x00007f42a9bc8000)
libm.so.6 => /home/hl/lib/libm.so.6 (0x00007f42a98c5000)
/home/hl/lib/ld-linux-x86-64.so.2 => /lib64/ld-linux-x86-64.so.2 (0x00007f42aa6c9000)
/usr/lib/x86_64-linux-gnu/libstdc++.so.6肯定存在

。。。但是你的libc看起来不在那里

您可以这样设置您的RPATH:
-Wl,-RPATH=/home/hl/lib:/usr/lib
,或者您可以编辑
/home/hl/etc/ld.so.conf
,并告诉您的libc查看
/usr/lib
(在
/home/hl/lib
之后)

这是一个权限问题吗?我不能混合使用root所有和用户所有的lib吗


不需要。你完全可以混合和匹配根拥有的库和用户拥有的库。

我将/usr/lib/x86_64-linux-gnu/libstdc++.so.6复制到/home/hl/lib中,它成功了。这是一个权限问题吗?我不能混合使用root所有和用户所有的lib吗?