Search code examples
macoslinkerdylib

Error when making dynamic lib from .o


I'm trying to make dynamic lib from set of .o files, but when i do

gcc -dynamiclib -current_version 1.0 mymod.o -o mylib.dylib

or

ld *.o -o mylib.dylib

i get a lot of errors like:

"_objc_msgSend", referenced from: -[NSObject(NSObject_SBJSON) JSONFragment] in NSObject+SBJSON.o

"operator new(unsigned long)", referenced from: MStatistic::instance() in MStatistic.o StatisticProfileLoggingObserver::instance() in StatisticObserver.o

ld: symbol(s) not found for architecture x86_64

Can you please help me, how to solve it and get my .dylib?


Solution

  • You can pass -undefined dynamic_lookup as an option to ld, or:
    -Wl,-undefined -Wl,dynamic_lookup to gcc or clang (which passes it to the linker).