ld 报告缺少符号,但符号似乎存在
我正在尝试将我的 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
我对此进行了稍微编辑以删除非常长的目标文件列表)。
什么可能导致此链接失败?该符号存在,并且是公共的,并且不存在无法找到库的错误或任何其他错误消息。
I'm trying to link my mac application to the wonderful libancillary library. However, I have changed the library build script to create a shared library. I can inspect the symbols in this library using nm libancillary.dylib
- the result is:
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
However, when I try and link my application, the output I get is:
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
(I have edited this slightly to remove the very long list of object files).
What could cause this linkage to fail? The symbol exists, and is public, and there's no error about not being able to find the library, or any other error messages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这些符号是未损坏的 C 符号。由于您已将其标记为 C++,因此我假设您正在使用 C++ 进行编译。如果这样做,您可能需要将库头文件包装在代码中的 extern 块中:
其中library.h 是库头文件的名称,以防止它们在调用代码中被破坏。
Those symbols are unmangled C symbols. As you have tagged this as C++, I assume you are compiling with C++. If you do that you may need to wrap your libraries header files in an extern block in your code:
where library.h is the name of the library's header file(s), to prevent them being mangled in the calling code.
我想知道这是否是一个 C++ 名称重整问题?
尝试在
utils.o
文件上运行nm
,看看它实际上在寻找什么符号。您可能必须将标头包装在
extern C
中。I wonder if it's a C++ name-mangling problem?
Try running
nm
on theutils.o
file, and see what symbol it's actually looking for.You might have to wrap the header in
extern C
.