代码之家  ›  专栏  ›  技术社区  ›  Thomi

LD报告缺少符号,但符号似乎存在

  •  6
  • Thomi  · 技术社区  · 14 年前

    我正试图将我的Mac应用程序链接到 libancillary 图书馆。但是,我已更改库生成脚本以创建共享库。我可以使用 nm libancillary.dylib -结果是:

    libancillary.dylib(single module):
             U ___sF
             U __keymgr_get_and_lock_processwide_ptr
             U __keymgr_get_and_lock_processwide_ptr_2
             U __keymgr_set_and_unlock_processwide_ptr
             U _abort
    00002cfe T _ancil_recv_fd
    00002c87 T _ancil_recv_fds
    00002b6a T _ancil_recv_fds_with_buffer
    00002e9e T _ancil_send_fd
    00002e27 T _ancil_send_fds
    00002d3f T _ancil_send_fds_with_buffer
             U _calloc
             U _dlopen
             U _dlsym
             U _fflush
             U _fprintf
             U _free
             U _malloc
             U _recvmsg
             U _sendmsg
    

    但是,当我尝试链接我的应用程序时,得到的输出是:

    g++ -headerpad_max_install_names -framework AppKit -framework Cocoa -framework IOKit -framework CoreFoundation -framework Carbon -framework OpenGL -framework SystemConfiguration -framework Security -Wl,-bind_at_load -arch i386 -o MyApp build/app.o build/client.o build/util.o -F/Library/Frameworks -L/Library/Frameworks -L../ancillary -lancillary
    Undefined symbols:
      "ancil_recv_fd(int, int*)", referenced from:
          CIPCUnixUtils::readFD(int, int&) constin utils.o
      "ancil_send_fd(int, int)", referenced from:
          CIPCUnixUtils::writeFD(int, int) constin utils.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [ABClient] Error 1
    

    (我对此进行了一些编辑,以删除非常长的对象文件列表)。

    什么会导致这种联系失败?该符号存在,并且是公共的,找不到库或任何其他错误消息都不会出错。

    2 回复  |  直到 14 年前
        1
  •  7
  •   anon    14 年前

    这些符号是未组合的C符号。当你把它标记为C++时,我假设你正在用C++编译。如果这样做,则可能需要在代码的外部块中包装库头文件:

    extern "C" {
    #include "library.h"
    }
    

    其中library.h是库头文件的名称,以防止它们在调用代码中被损坏。

        2
  •  1
  •   Douglas Leeder    14 年前

    我想知道这是否是一个C++名字处理问题?

    试运行 nm utils.o 文件,看看它到底在找什么符号。

    你可能得把头包起来 extern C .