【问题标题】:ldconfig doesn't recognise new library in directoryldconfig 无法识别目录中的新库
【发布时间】:2021-08-28 00:22:27
【问题描述】:

我正在尝试编译一个需要 libpthreads.so 的包。我的系统(Ubuntu 20.04)有 libpthread.so(线程末尾没有's')。

我尝试将 libpthreads.so 链接到 libpthread.so,但 ldconfig 无法识别新文件。我这样做了:

> cd /lib/x86_64-linux-gnu
> ln -s libpthread-2.31.so libpthreads.so
> rm  /etc/ld.so.cache
> ldconfig

我运行了几次“ldconfig”,然后检查它是否找到了新库:

> ldconfig -p | grep libpthrea
        libpthread.so.0 (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib/x86_64-linux-gnu/libpthread.so.0
        libpthread.so (libc6,x86-64, OS ABI: Linux 3.2.0) => /lib/x86_64-linux-gnu/libpthread.so

为什么 ldconfig 没有找到新的库(它只找到了原来的 libpthread.so,而不是 libpthreads.so)?

我也尝试制作副本(而不是符号链接),但这没有帮助。

文件所在的目录(/lib/x86_64-linux-gnu)对于链接器来说是已知的:

> ld --verbose | grep SEARCH_DIR | tr -s ' ;' \\012
SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu")
SEARCH_DIR("=/lib/x86_64-linux-gnu")              <---- this directory
SEARCH_DIR("=/usr/lib/x86_64-linux-gnu")
SEARCH_DIR("=/usr/lib/x86_64-linux-gnu64")
SEARCH_DIR("=/usr/local/lib64")
SEARCH_DIR("=/lib64")
SEARCH_DIR("=/usr/lib64")
SEARCH_DIR("=/usr/local/lib")
SEARCH_DIR("=/lib")
SEARCH_DIR("=/usr/lib")
SEARCH_DIR("=/usr/x86_64-linux-gnu/lib64")
SEARCH_DIR("=/usr/x86_64-linux-gnu/lib")

【问题讨论】:

    标签: ubuntu linker shared-libraries ld


    【解决方案1】:

    我尝试将 libpthreads.so 链接到 libpthread.so,但 ldconfig 无法识别新文件。

    不需要 ldconfig 来识别这个库。您只需要链接器识别它(它将)链接它。

    一旦你链接你的程序(如果你成功了),二进制文件将记录它需要libpthread.so.0(因为那是libpthread.soSONAME),并且ldconfig确实知道如何找到它。

    附:如果不进行修改,您可能无法实际构建您的程序——pthreads 可能对应于真正古老的 POSIX 线程标准,因此函数原型将不匹配。 如果需要修改程序,不妨将其链接行改为-lpthread(不带s)。

    【讨论】:

      猜你喜欢
      • 2021-08-26
      • 1970-01-01
      • 2015-11-09
      • 1970-01-01
      • 2021-07-01
      • 2021-05-13
      • 2014-07-10
      • 2021-09-16
      • 1970-01-01
      相关资源
      最近更新 更多