Error when making dynamic lib from .o

纵饮孤独 提交于 2019-12-23 04:50:29

问题


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?


回答1:


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).




回答2:


From this line:

ld: symbol(s) not found for architecture x86_64

it sounds like you are building some libraries that have make files that only build for 32-bit architectures.

You need to modify the makefiles for all the libraries / frameworks you're building to build both 32-bit and 64-bit; and in a practical sense, all shipping MacOS machines are 64-bit capable so it may just be safe to build only for 64-bit.

In your compile / linking lines, add something like this: "-arch x86_64" and that should compile things for the 64-bit side. To do both 32 & 64-bit, you'll basically need to duplicate the compile & link lines with their own "-arch i386" and "-arch x86_64" lines.



来源:https://stackoverflow.com/questions/14090257/error-when-making-dynamic-lib-from-o

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!