简体   繁体   English

无法将C ++与Xcode 5联系起来

[英]Trouble linking C++ with Xcode 5

So I have this legacy project, which I am trying to bring to iOS 7 and Xcode 5. And by legacy, I mean real legacy. 所以我有这个遗留项目,我试图将其带入iOS 7和Xcode 5.而传统,我的意思是真正的遗产。 Like 2004 legacy. 像2004年的遗产。

Anyhow, I am trying to build this thing, and it spits out a few libraries, including some common third party libs. 无论如何,我正在尝试构建这个东西,它会吐出一些库,包括一些常见的第三方库。 When linking, I get errors like these: 链接时,我得到这样的错误:

Undefined symbols for architecture ${arch}:
  "google::protobuf::internal::WireFormatLite::WriteBytes(int, std::string const&, google::protobuf::io::CodedOutputStream*)"

Upon examination with nm , the old (arm only) binary library still included in the project contains this: 在使用nm检查时,项目中仍包含的旧(仅限arm)二进制库包含以下内容:

         U __ZN6google8protobuf8internal14WireFormatLite10WriteBytesEiRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEPNS0_2io17CodedOutputStreamE
00000a8c T __ZN6google8protobuf8internal14WireFormatLite10WriteBytesEiRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEPNS0_2io17CodedOutputStreamE
00002b28 S __ZN6google8protobuf8internal14WireFormatLite10WriteBytesEiRKNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEEPNS0_2io17CodedOutputStreamE.eh</code>

The new library (universal), created when I run the project through Xcode 5 (and thus, clang/llvm) contains this: 我通过Xcode 5(因此,clang / llvm)运行项目时创建的新库(通用)包含:

         U __ZN6google8protobuf8internal14WireFormatLite10WriteBytesEiRKSsPNS0_2io17CodedOutputStreamE
00000514 T __ZN6google8protobuf8internal14WireFormatLite10WriteBytesEiRKSsPNS0_2io17CodedOutputStreamE
00000b2c S __ZN6google8protobuf8internal14WireFormatLite10WriteBytesEiRKSsPNS0_2io17CodedOutputStreamE.eh

To me, it looks like the parameters are missing in the mangled name. 对我来说,看起来错误的名称中缺少参数。

Is this normal and I need to look somewhere else? 这是正常的,我需要看看别的地方吗?

Or if this is the problem: Any idea how to solve it? 或者如果这是问题:任何想法如何解决?

EDIT: I mixed up OLD and NEW. 编辑:我混淆了OLD和NEW。 I left the original post unchanged 我原来的帖子保持不变

The old, arm only libary seems to indicate: 旧的,只有手臂的图书馆似乎表明:

google::protobuf::internal::WireFormatLite::WriteBytes(int, std::string const&, google::protobuf::io::CodedOutputStream*)

Which has all the hallmarks of being compiled with libstdc++. 其中包含使用libstdc ++编译的所有标志。

The new universal library indicates: 新的通用库表明:

google::protobuf::internal::WireFormatLite::WriteBytes(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, google::protobuf::io::CodedOutputStream*)

This has all the hallmarks of being compiled with libc++ 这具有使用libc ++编译的所有标志

Your link error indicates that there is a problem finding: 您的链接错误表明找不到问题:

 google::protobuf::internal::WireFormatLite::WriteBytes(int, std::string const&, google::protobuf::io::CodedOutputStream*)

This would be the case if the code linking to the library was compiled using libstdc++ and, because your new universal library is compiled using libc++ the code will not link. 如果链接到库的代码是使用libstdc++编译的,那么就是这种情况,因为你的新通用库是使用libc++编译的,代码不会链接。

You have to compile everything with the same libc++/libstdc++ support, you cannot mix and match as they will refuse to link. 您必须使用相同的libc ++ / libstdc ++支持编译所有内容 ,您不能混合和匹配,因为它们将拒绝链接。 Make sure that every element in your project is compiled using the same C++ Standard Library and the link error should be resolved. 确保项目中的每个元素都使用相同的C ++标准库进行编译,并且应该解决链接错误。

In general, demangling the symbols (using c++filt ) allows you to see the proper signatures, and in the case of this code, once you start seeing std::__1:: in the symbols, it indicates that the library was compiled using libc++ , and when you see the link failing with unadorned std:: symbols (ie without the inner __1:: ), then it indicates that the item performing the linking is using libstdc++ . 通常,对符号进行解码(使用c++filt )允许您查看正确的签名,对于此代码,一旦您开始在符号中看到std::__1:: ,它表示库已编译使用libc++ ,当你看到链接失败时,使用__1:: std:: symbols(即没有内部__1:: ,那么它表明执行链接的项目正在使用libstdc++

Are you perhaps mixing and matching SDKs or compilers? 您是混合和匹配SDK还是编译器? Name mangling might differ between compilers. 名称重整可能在编译器之间有所不同。 The only other thing I know that might affect name mangling is the 'extern "C"' keyword, but that usually turns it off completely, so I don't think that's it. 我所知道的唯一可能影响名称修改的另一件事是'extern“C”'关键字,但通常会完全关闭它,所以我不认为就是这样。

So, if the old code was still built with GCC 2.x and your new code is clang-built, they probably just mangle differently. 因此,如果旧代码仍然使用GCC 2.x构建并且您的新代码是clang-built,那么它们可能只是以不同方式进行修改。

Does the error message really say $(arch) ? 错误消息真的说$(arch)吗? Not a particular architecture? 不是特定的架构? If it gave a concrete architecture, I'd expect that you have one project that builds eg for arm5 and arm6, linking in a library that only has one of these architectures. 如果它给出了一个具体的架构,我希望你有一个项目,例如为arm5和arm6构建,链接在一个只有这些架构之一的库中。 Then it usually complains about the symbols in that library not being available, I think. 然后它通常会抱怨该库中的符号不​​可用,我想。

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

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