CocoaPods:与libPods.a中定义的C ++符号链接

时间:2013-05-16 16:57:52

标签: cocoa cocoapods clang++

我最近开始研究将levelDB集成到我的项目中的podSpec文件。 (https://github.com/iljaiwas/Podspecs/blob/master/LevelDBPodSpec/0.0.1/leveldb.podspec

但是,当我从主目标中的.mm文件引用任何C ++符号时,我得到如下链接器错误:

Undefined symbols for architecture x86_64:
 "leveldb::DB::Open(leveldb::Options const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, leveldb::DB**)", referenced  from:
  -[IHLevelDBContext initWithPath:] in IHLevelDBContext.o

这就是编译器调用的样子

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -L/Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Products/Debug -F/Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Products/Debug -filelist /Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Intermediates/LevelDBTest2.build/Debug/LevelDBTest2.build/Objects-normal/x86_64/LevelDBTest2.LinkFileList -mmacosx-version-min=10.7 -ObjC -fobjc-arc -fobjc-link-runtime -stdlib=libc++ -framework Cocoa -lPods -o /Users/ilja/Library/Developer/Xcode/DerivedData/LevelDBTest2-aiflqgbevhxzfxbrsdamteybrbao/Build/Products/Debug/LevelDBTest2.app/Contents/MacOS/LevelDBTest2 

根据我的理解,缺少的:: Open调用包含在libPods.a

nm libPods.a | grep "Open"

             U __ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_
000000000005e5b1 s L___func__._ZN7leveldb6DBImpl24OpenCompactionOutputFileEPNS0_15CompactionStateE
00000000000099d0 T __ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_
0000000000060ba0 S __ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_.eh

似乎我可以通过将主应用程序的“编译器”设置从Apple LLVM 4.2更改为LLVM GCC 4.2来解决链接器错误,但是此编译器会阻止Objective-C 2.0功能,如下所示:

expected a property attribute before 'strong' 

感谢关于我可能做错的任何指示, ILJA

2 个答案:

答案 0 :(得分:13)

您还可以在podspec文件中设置C ++配置设置:

  s.library = 'c++'
  s.xcconfig = {
       'CLANG_CXX_LANGUAGE_STANDARD' => 'c++11',
       'CLANG_CXX_LIBRARY' => 'libc++'
  }

这些设置选择为C ++ 2011编译并添加libc ++标准库。

答案 1 :(得分:1)

在我将应用程序目标和CocoaPods目标中的“C ++标准库”设置设置为“编译器默认值”后,问题就消失了。似乎默认情况下它们被设置为不兼容的值,这会导致链接器混淆。