【问题标题】:libmicrohttpd: undefined reference to `pthread_setname_np@GLIBC_2.12' when linkinglibmicrohttpd:链接时未定义对“pthread_setname_np@GLIBC_2.12”的引用
【发布时间】:2020-11-11 17:38:47
【问题描述】:

我在我的项目中使用 libmicrohttpd 0.9.53 并决定将其更新到最新版本 (0.9.71)。我正在为 ARM 进行交叉编译,这是 arm-linux-gcc --version 的输出:

arm-linux-gcc (4.4.4_09.06.2010) 4.4.4
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

/lib/arm-linux-gnueabi/libc.so.6的输出:

GNU C Library (Debian GLIBC 2.19-18+deb8u3) stable release version 2.19, by Roland McGrath et al.
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.8.4.
Compiled on a Linux 3.16.7 system on 2016-02-12.
Available extensions:
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        Native POSIX Threads Library by Ulrich Drepper et al
        BIND-8.2.3-T5B
libc ABIs: UNIQUE
For bug reporting instructions, please see:
<http://www.debian.org/Bugs/>.

编译成功,但是在链接共享库时出现以下错误:

arm-linux-gcc     -Llib/libmicrohttpd/lib -Wl,-rpath,./lib   -o "proj" build/src/proj.o -lpthread -lm -lmicrohttpd
lib/libmicrohttpd/lib/libmicrohttpd.so: undefined reference to `pthread_setname_np@GLIBC_2.12'
lib/libmicrohttpd/lib/libmicrohttpd.so: undefined reference to `clock_gettime@GLIBC_2.17'
collect2: ld returned 1 exit status
make: *** [makefile:191: proj] Error 1

在目标机器上,我跑了/lib/arm-linux-gnueabi/libc.so.6 | grep clock_gettime

782: 000e48e4   116 FUNC    GLOBAL DEFAULT   12 __clock_gettime@@GLIBC_PRIVATE
1625: 000e48e4   116 FUNC    WEAK   DEFAULT   12 clock_gettime@@GLIBC_2.17

readelf -Ws /lib/arm-linux-gnueabi/libc.so.6 | grep pthread_setname 没有给出任何结果。

显然,错误中提到的两个符号已添加在旧版本和新版本之间,并且我当前的 libc 版本似乎没有定义它们。 我在这里完全偏离轨道了吗?我必须以某种方式更新libc吗?您能否提出任何可以为我指明正确方向的建议?

【问题讨论】:

  • 完全推测:这可能是您的标志顺序的问题。试试:-lm -lmicrohttpd -lpthread.

标签: linker arm shared-libraries glibc ldd


【解决方案1】:

看起来您的工具链默认为 -Wl,--as-needed。在这种情况下,即使对于共享对象,链接顺序也很重要。

尝试用这个替换-lpthread -lm -lmicrohttpd

-lm -lmicrohttpd -lpthread

clock_gettime@GLIBC_2.17 问题需要在您的交叉构建环境中使用 glibc 版本进行重建。似乎它是在目标系统上编译的(根据您的问题,它具有 glibc 2.19),但它可以针对任何在 libc.so.6 中具有 clock_gettime 的版本构建,从 glibc 2.17 开始。您的交叉编译环境在该更改之前具有 glibc 版本(因此 glibc 2.16 或更早版本),因此它无法识别 clock_gettime@GLIBC_2.17 符号版本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-07
    • 2015-09-09
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 2011-04-03
    • 2021-08-17
    相关资源
    最近更新 更多