简体   繁体   English

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

[英]Statically linking a library into a C++ dylib on OSX

I am compiling a number of .dylibs (a plugins) and I want to statically include tinyxml2 into them. 我正在编译许多.dylibs(一个插件),我想将tinyxml2静态地包含在其中。 I've got tinyxml2.cpp and tinyxml2.h sitting next to the sources. 我在源代码旁边tinyxml2.htinyxml2.cpptinyxml2.h When I run my make, the commands it produces are: 当我运行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

How should I proceed to make it link? 我应该如何进行链接? (I want all the .dylibs that I am building to include the tinyxml2 lib statically, preferably with namespace mangling). (我希望构建的所有.dylibs都静态地包含tinyxml2 lib,最好使用名称空间修改)。

Note that I am using the older 10.5 SDK here - I have to since my host application uses it. 请注意,我在这里使用的是较旧的10.5 SDK-自从主机应用程序使用它以来,我就必须这样做。

When linking you'll to specify all object files needed. 链接时,您将指定所有需要的目标文件。 So add tinyxml2.a after SyGeo.os when linking to create SyGeo.dylib . 所以加tinyxml2.aSyGeo.os链接创建时SyGeo.dylib

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM