Ld reports missing characters, but characters seem to exist

I am trying to link my mac application with the wonderful libancillary library. However, I created a build script library to create a shared library. I can check the characters in this library with 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 to 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 edited this a bit to remove a very long list of object files).

What could lead to the failure of this connection? The symbol exists and is publicly accessible, and there is no error that you cannot find the library or any other error messages.

+6
c ++ gcc linker macos undefined-symbol
source share
2 answers

These characters are unencrypted C characters. Since you marked this as C ++, I assume that you are compiling with C ++. If you do this, you may need to wrap the library header files in an extern block in your code:

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

where library.h is the name of the library header file (s) to prevent them from being distorted in the calling code.

+7
source share

Interestingly, a problem with C ++ change?

Try running nm in utils.o and see what character it is really looking for.

You may need to wrap the header in extern C

+1
source share

All Articles