【问题标题】:Link against different glibc链接到不同的 glibc
【发布时间】:2013-08-15 05:37:51
【问题描述】:

我将 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 复制到 /home/hl/lib 中,它工作正常。是权限问题,我不能混合 root 拥有和用户拥有的库吗?

标签: linker g++ glibc


【解决方案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 拥有和用户拥有的库吗?

没有。您可以绝对混合和匹配 root 拥有的库和用户拥有的库。

【讨论】:

    猜你喜欢
    • 2014-07-01
    • 2013-01-12
    • 1970-01-01
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    相关资源
    最近更新 更多