在OSX上将库静态链接到C++dylib中
Statically linking a library into a C++ dylib on OSX
我正在编译许多.dlib(一个插件),我想静态地将tinyxml2包含在其中。我把tinyxml2.cpp
和tinyxml2.h
放在源旁边。当我运行make时,它产生的命令是:
rm -rf *.a *.os *.dylib
g++-4.0 -g -c -Werror -DUSE_GLEW -I/Applications/Nuke6.3v4/Nuke6.3v4.app/Contents/MacOS/include -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch x86_64 tinyxml2.cpp -o tinyxml2.a
g++-4.0 -g -c -Werror -DUSE_GLEW -I/Applications/Nuke6.3v4/Nuke6.3v4.app/Contents/MacOS/include -isysroot /Developer/SDKs/MacOSX10.5.sdk -arch x86_64 -o SyGeo.os SyGeo.cpp
g++-4.0 -L/Applications/Nuke6.3v4/Nuke6.3v4.app/Contents/MacOS -Wl,-syslibroot,/Developer/SDKs/MacOSX10.5.sdk -arch x86_64 -bundle -lDDImage -lGLEW -framework QuartzCore -framework IOKit -framework CoreFoundation -framework Carbon -framework ApplicationServices -framework OpenGL -framework AGL -o SyGeo.dylib SyGeo.os
Undefined symbols:
"tinyxml2::XMLDocument::LoadFile(char const*)", referenced from:
SyDistorter::readPreset() in SyGeo.os
"tinyxml2::XMLDocument::~XMLDocument()", referenced from:
SyDistorter::readPreset() in SyGeo.os
SyDistorter::readPreset() in SyGeo.os
"tinyxml2::XMLElement::FindAttribute(char const*) const", referenced from:
tinyxml2::XMLElement::QueryFloatAttribute(char const*, float*) constin SyGeo.os
"tinyxml2::XMLNode::NextSiblingElement(char const*) const", referenced from:
tinyxml2::XMLNode::NextSiblingElement(char const*)in SyGeo.os
"tinyxml2::XMLDocument::XMLDocument(bool)", referenced from:
SyDistorter::readPreset() in SyGeo.os
"tinyxml2::XMLNode::FirstChildElement(char const*) const", referenced from:
tinyxml2::XMLNode::FirstChildElement(char const*)in SyGeo.os
"tinyxml2::XMLAttribute::QueryFloatValue(float*) const", referenced from:
tinyxml2::XMLElement::QueryFloatAttribute(char const*, float*) constin SyGeo.os
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [SyGeo.dylib] Error 1
我应该如何使其链接?(我希望我正在构建的所有.dlib都静态地包含tinyxml2-lib,最好是带有名称空间的mangling)。
请注意,我在这里使用的是旧的10.5 SDK,因为我的主机应用程序使用了它,所以我不得不这样做。
链接时,您将指定所需的所有对象文件。因此在链接时在SyGeo.os
之后添加tinyxml2.a
以创建SyGeo.dylib
。
相关文章:
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- CMake-按正确顺序将项目与C运行时对象文件链接
- 从链接列表c++中删除一个项目
- 有根的二进制搜索树.保留与其父级的链接
- 读取文件的最后一行并输入到链接列表时出错
- 静态数据成员的问题-修复链接错误会导致编译器错误
- node-gyp 在 macOS 上未正确链接库
- 基于boost的程序的静态链接——zlib问题
- 无法链接 CMake 中的本地库
- 内联函数中具有内部链接的全局变量
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 使用gcc从静态链接的文件中查找可选符号
- 我可以将一个用clang c++11编译的对象与另一个用c++17编译的对象链接起来吗
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 下面是我为检测链接列表中的循环而制作的代码
- 有了gcc,是否可以链接库,但前提是它存在
- MacOS QT项目中的链接Dylib
- 动态链接是如何工作的,它的用法以及如何以及为什么要制作dylib
- 使用 clang/LLVM 通过 LDFLAGS 链接 .dylib
- G++:链接动态(dylib)库