0

我将 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)
4

1 回答 1

1

/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).j

这是一个权限问题,我不能混合 root 拥有和用户拥有的库吗?

不,您绝对可以混合和匹配根拥有和用户拥有的库。

于 2013-08-15T21:39:21.020 回答