【问题标题】:Can't link against `libPocoFoundation` Poco C++ Framework无法链接到`libPocoFoundation` Poco C++ 框架
【发布时间】:2013-11-17 20:54:54
【问题描述】:

在我的 Linux 工作站上安装 Poco 后(我尝试了两个 - 来自源的最新版本和来自 apt-get 包管理器的旧版本)我无法链接到 libPocoFoundation

当我尝试使用 g++ 编译任何代码时,在附加了 -lPocoFoundation 标志后,我会收到如下错误:

$ g++ -std=c++0x -lPocoFoundation main.cpp -o main
    main.cpp:(.text+0xc6): undefined reference to `Poco::ThreadPool::joinAll()
    main.cpp:(.text+0xb1): undefined reference to `Poco::ThreadPool::available()

我明确检查了libPocoFoundation.so 是否存在于我的/usr/local/lib/ 目录中,没关系。

为什么链接器找不到 Poco 共享库?

下面是readelf -s的DUMP的摘录:

Symbol table '.dynsym' contains 5732 entries:
   Num:    Value  Size Type    Bind   Vis      Ndx Name
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 FUNC    GLOBAL DEFAULT  UND waitpid@GLIBC_2.0 (2)
     2: 00000000     0 OBJECT  GLOBAL DEFAULT  UND _ZTIi@CXXABI_1.3 (3)
     3: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_mutex_destroy@GLIBC_2.0 (2)
     4: 00000000     0 FUNC    GLOBAL DEFAULT  UND _ZNSo3putEc@GLIBCXX_3.4 (4)
     5: 00000000     0 FUNC    GLOBAL DEFAULT  UND chmod@GLIBC_2.0 (5)
     6: 00000000     0 FUNC    GLOBAL DEFAULT  UND getrusage@GLIBC_2.0 (5)
     7: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_getspecific@GLIBC_2.0 (2)
     8: 00000000     0 FUNC    GLOBAL DEFAULT  UND _ZNSt15basic_streambufIcS@GLIBCXX_3.4 (4)
     9: 00000000     0 FUNC    GLOBAL DEFAULT  UND _Znwj@GLIBCXX_3.4 (4)
    10: 00000000     0 FUNC    GLOBAL DEFAULT  UND _ZNSt8__detail15_List_nod@GLIBCXX_3.4.15 (6)
   206: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_join@GLIBC_2.0 (2)
   211: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_rwlock_rdlock@GLIBC_2.1 (8)
   223: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_setschedparam@GLIBC_2.0 (2)
   224: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_cond_timedwait@GLIBC_2.3.2 (16)
   227: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_cond_wait@GLIBC_2.3.2 (16)
   246: 00000000     0 FUNC    GLOBAL DEFAULT  UND pthread_self@GLIBC_2.0 (2)

readelf -S:

There are 29 section headers, starting at offset 0x1a1cdc:

Section Headers:
  [Nr] Name              Type            Addr     Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            00000000 000000 000000 00      0   0  0
  [ 1] .note.gnu.build-i NOTE            00000114 000114 000024 00   A  0   0  4
  [ 2] .gnu.hash         GNU_HASH        00000138 000138 00a4d8 04   A  3   0  4
  [ 3] .dynsym           DYNSYM          0000a610 00a610 016640 10   A  4   1  4
  [ 4] .dynstr           STRTAB          00020c50 020c50 03677f 00   A  0   0  1
  [ 5] .gnu.version      VERSYM          000573d0 0573d0 002cc8 02   A  3   0  2
  [ 6] .gnu.version_r    VERNEED         0005a098 05a098 000220 00   A  4   7  4
  [ 7] .rel.dyn          REL             0005a2b8 05a2b8 008700 08   A  3   0  4
  [ 8] .rel.plt          REL             000629b8 0629b8 003598 08   A  3  10  4
  [ 9] .init             PROGBITS        00065f50 065f50 00002e 00  AX  0   0  4
  [10] .plt              PROGBITS        00065f80 065f80 006b40 04  AX  0   0 16
  [11] .text             PROGBITS        0006cac0 06cac0 0d89d8 00  AX  0   0 16
  [12] .fini             PROGBITS        00145498 145498 00001a 00  AX  0   0  4
  [13] .rodata           PROGBITS        001454c0 1454c0 01c8e0 00   A  0   0 32
  [14] .eh_frame_hdr     PROGBITS        00161da0 161da0 00732c 00   A  0   0  4
  [15] .eh_frame         PROGBITS        001690cc 1690cc 024140 00   A  0   0  4
  [16] .gcc_except_table PROGBITS        0018d20c 18d20c 00bc6c 00   A  0   0  4
  [17] .init_array       INIT_ARRAY      001997e0 1997e0 000084 00  WA  0   0  4
  [18] .ctors            PROGBITS        00199864 199864 000008 00  WA  0   0  4
  [19] .dtors            PROGBITS        0019986c 19986c 000008 00  WA  0   0  4
  [20] .jcr              PROGBITS        00199874 199874 000004 00  WA  0   0  4
  [21] .data.rel.ro      PROGBITS        00199880 199880 005d14 00  WA  0   0 32
  [22] .dynamic          DYNAMIC         0019f594 19f594 000108 08  WA  4   0  4
  [23] .got              PROGBITS        0019f69c 19f69c 000950 04  WA  0   0  4
  [24] .got.plt          PROGBITS        0019fff4 19fff4 001ad8 04  WA  0   0  4
  [25] .data             PROGBITS        001a1acc 1a1acc 0000e4 00  WA  0   0  4
  [26] .bss              NOBITS          001a1bc0 1a1bb0 0007a8 00  WA  0   0 32
  [27] .comment          PROGBITS        00000000 1a1bb0 00002a 01  MS  0   0  1
  [28] .shstrtab         STRTAB          00000000 1a1bda 000101 00      0   0  1

【问题讨论】:

    标签: c++ linker g++ shared-libraries poco


    【解决方案1】:

    尝试nm --demangle /usr/local/lib/libPocoFoundation.so 并检查这些符号是否在那里定义。

    如果符号在nm 输出的左栏中有U,则它是未定义的,您必须在其他地方找到它。

    【讨论】:

    • 它说“没有符号”!?!?这怎么可能?我错过了什么?
    • @ItayGrudev 它可能会为另一个平台编译。尝试readelf -h 并检查Class:Machine: 字段。
    • Class: ELF32Machine: Intel 80386。这是正确的,但仍然没有找到符号。我什至尝试了最新版本1.5.2,但仍然遇到同样的问题。
    • 对于初学者来说,readelf -s 表示确实没有这样的符号(您可能需要查看 demangled 版本才能确定,可以使用 nm --demangle)。
    • 啊,您从readelf -s 输出中发布了摘录。您需要做的是使用nm --demangle 并查找被提及为未定义的符号。您可以按照我在答案中的描述确定这一点。
    猜你喜欢
    • 2013-03-23
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-14
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多