在OSX上将库静态链接到C++dylib中

Statically linking a library into a C++ dylib on OSX

本文关键字:链接 C++dylib 静态 OSX      更新时间:2023-10-16

我正在编译许多.dlib(一个插件),我想静态地将tinyxml2包含在其中。我把tinyxml2.cpptinyxml2.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