我已经在 OSX 上编译了一个具有一些外部依赖项(boost,OpenGL)的共享库:
g++ -dynamiclib -undefined suppress -flat_namespace -o "libMY_LIB.dylib" ./windowbase.o -lGL -lGLU -lGLUT -lboost_system -lboost_thread
没有错误、file libMY_LIB.dylib
结果Mach-O 64-bit dynamically linked shared library x86_64
和otool -L libMY_LIB.dylib
输出:
libPixelsGL.dylib (compatibility version 0.0.0, current version 0.0.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib (compatibility version 1.0.0, current version 1.0.0)
/System/Library/Frameworks/GLUT.framework/Versions/A/GLUT (compatibility version 1.0.0, current version 1.0.0)
libboost_system.dylib (compatibility version 0.0.0, current version 0.0.0)
libboost_thread.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
现在我尝试将可执行文件链接到libMY_LIB.dylib
,仅使用MY_LIB.h
(并在 lib 中编译)中的函数:
g++ -L"/path/to/MY_LIB" -o "Program" ./main.o -lMY_LIB
但它失败了,打印:
Undefined symbols for architecture x86_64:
"boost::system::system_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in main.o
boost::mutex::mutex()in main.o
boost::mutex::lock() in main.o
boost::mutex::unlock() in main.o
"boost::system::generic_category()", referenced from:
__static_initialization_and_destruction_0(int, int)in main.o
"boost::thread::detach()", referenced from:
boost::thread::~thread()in main.o
ld: symbol(s) not found for architecture x86_64
一些解释和/或帮助?
谢谢!
编辑
我试图将没有-undefined suppress -flat_namespace
标志的lib和可执行文件与它们链接起来,后者起作用了。谁能告诉我为什么?可能是我用这些标志编译的提升库吗?
再次感谢!