将Objective-C应用程序链接到C ++静态库 [英] Link Objective-C application to C++ static library

查看:178
本文介绍了将Objective-C应用程序链接到C ++静态库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Xcode构建一个Objective-C桌面应用程序,链接到一个静态C ++库。我使用的是苹果的clang编译器。我收到以下链接器错误:

I am trying to use Xcode to build an Objective-C desktop application that links against a static C++ library. I am using the Apple's clang compiler. I am getting the following linker error:

Apple clang version 3.0 (tags/Apple/clang-211.12) (based on LLVM 3.0svn)
Target: x86_64-apple-darwin11.2.0
Thread model: posix
 "/Developer/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.7.0 -syslibroot /Developer/SDKs/MacOSX10.7.sdk -o /Users/andrew/Library/Developer/Xcode/DerivedData/sl-marketplace-analysis-exomzzahbygseghhwoeclcvpooeo/Build/Products/Debug/sl marketplace analyitics.app/Contents/MacOS/sl marketplace analyitics -lcrt1.10.6.o -L/Users/andrew/Library/Developer/Xcode/DerivedData/sl-marketplace-analysis-exomzzahbygseghhwoeclcvpooeo/Build/Products/Debug -L/Users/andrew/Projects/sl-marketplace-analysis/platform/mac/sl marketplace analyitics/../../../../../Library/Developer/Xcode/DerivedData/sl-marketplace-analysis-exomzzahbygseghhwoeclcvpooeo/Build/Products/Debug -filelist /Users/andrew/Library/Developer/Xcode/DerivedData/sl-marketplace-analysis-exomzzahbygseghhwoeclcvpooeo/Build/Intermediates/sl marketplace analyitics.build/Debug/sl marketplace analyitics.build/Objects-normal/x86_64/sl marketplace analyitics.LinkFileList -framework Cocoa -lcore -lSystem /Developer/usr/bin/../lib/clang/3.0/lib/darwin/libclang_rt.osx.a -F/Users/andrew/Library/Developer/Xcode/DerivedData/sl-marketplace-analysis-exomzzahbygseghhwoeclcvpooeo/Build/Products/Debug
Undefined symbols for architecture x86_64:
  "std::ios_base::Init::~Init()", referenced from:
      ___cxx_global_var_init in libcore.a(test.o)
  "std::ios_base::Init::Init()", referenced from:
      ___cxx_global_var_init in libcore.a(test.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

似乎它不是链接到C ++ std库。

It seems like it isn't linking against the C++ std library. Is this the problem and if so, how to I ensure that it links against it?

更新

如果我添加一个空的cpp文件到构建然后一切编译和运行良好。我只是似乎需要一种方法来告诉链接器链接到C ++ std库。我尝试查看Xcode中的所有构建设置,但似乎找不到任何有帮助的。

If I add a blank cpp file to the build then everything compiles and runs fine. I just seem to need a way to tell the linker to link against the C++ std library. I have tried looking through all of the build settings in Xcode but can't seem to find anything that helps.

推荐答案

-lstdc ++或-lc ++(取决于静态库期望的C ++运行时)
到Build Setting下的Other Linker Flags:

Try adding -lstdc++ or -lc++ (depending on which C++ runtime your static library expects) to "Other Linker Flags" under "Build Setting":

>

这篇关于将Objective-C应用程序链接到C ++静态库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆