CocoaPods:链接到libPods.a中定义的C ++符号 [英] CocoaPods: Linking with C++ symbols defined in libPods.a

查看:791
本文介绍了CocoaPods:链接到libPods.a中定义的C ++符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始工作在一个podSpec文件,将levelDB集成到我的项目。
https://github.com/但是,当我从.mm文件中引用任何C ++符号时,会出现这样的情况:

在主目标,我得到一个链接器错误,像这样:

 架构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 **),引用自:
- IHLevelDBContext.o中的[IHLevelDBContext initWithPath:]


$ b b

这是编译器调用的样子。

  /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 / 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- 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的打开

ü__ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_
000000000005e5b1。S L ___ FUNC __._ ZN7leveldb6DBImpl24OpenCompactionOutputFileEPNS0_15CompactionStateE
00000000000099d0牛逼__ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_
0000000000060ba0小号__ZN7leveldb2DB4OpenERKNS_7OptionsERKSsPPS0_.eh

看来我可以通过将主程序的编译器设置从Apple LLVM 4.2更改为LLVM GCC 4.2来解决链接器错误,阻塞了Objective-C 2.0的特性,像这样:

 预期'strong'前的属性属性
Ilja

解决方案

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

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



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


I recently started working on a podSpec file that integrates levelDB into my projects. (https://github.com/iljaiwas/Podspecs/blob/master/LevelDBPodSpec/0.0.1/leveldb.podspec)

However, when I reference any C++ symbol from a .mm file in the main target, I get a linker error like this:

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

This is what the compiler invocation looks like

/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 

From my understanding, the missing ::Open call is included in 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

It seems I can get around the linker errors by changing the "Compiler" setting for the main app from Apple LLVM 4.2 to LLVM GCC 4.2, but this compiler chokes on Objective-C 2.0 features, like this:

expected a property attribute before 'strong' 

Thanks for any pointers on what I might be doing wrong, Ilja

解决方案

You can also set the C++ config settings in the podspec file:

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

Those settings selects to compile for C++ 2011 and adds the libc++ standard library.

这篇关于CocoaPods:链接到libPods.a中定义的C ++符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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