xcode IOS7(仅)stdlibc++ 链接问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18959691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IOS7 (only) stdlibc++ linking issue
提问by MarekM
I need help. I had a framwork which was using stdc++ like std:string. Now when i have created new app for IOS7 only there is problem with linking this framework because of problems with stdc++ lib:
我需要帮助。我有一个使用 stdc++ 的框架,如 std:string。现在,当我仅为 IOS7 创建新应用程序时,由于 stdc++ lib 存在问题,链接此框架时出现问题:
Undefined symbols for architecture armv7 "std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage", referenced from ...
架构 armv7 的未定义符号“std::basic_string, std::allocator >::_Rep::_S_empty_rep_storage”,引用自 ...
I have find out something strange that when i change the Deplyment target to ios6 in this app all is working fine. With ios7 i see errors.
我发现一些奇怪的事情,当我在这个应用程序中将 Deplyment 目标更改为 ios6 时,一切正常。使用 ios7 我看到错误。
I already have flag set in other linker flags: -lstdc++
我已经在其他链接器标志中设置了标志:-lstdc++
Any idea what ami doing wrong?
知道我做错了什么吗?
采纳答案by Doug Knowles
Just an update on this answer:
只是对这个答案的更新:
This step is very important!
这一步很重要!
Ensure that C++ Standard Libraryis set to libstdc++ (GNU c++ standard library)in the Apple LLVM 5.0 Compiler Build Settings
确保在 Apple LLVM 5.0 编译器构建设置中将C++ 标准库设置为libstdc++(GNU c++ 标准库)
Background:
背景:
I have an iOS app that abruptly stopped building for iOS 7 with standard library link errors. I had been testing the app successfully on the simulator and on an iPad mini, and archived it as well, but when I added an iPhone 5S for testing, I started getting link errors (possibly because of a new architecture in the mix?).
我有一个 iOS 应用程序,它突然停止为 iOS 7 构建,并出现标准库链接错误。我已经在模拟器和 iPad mini 上成功测试了该应用程序,并将其存档,但是当我添加 iPhone 5S 进行测试时,我开始出现链接错误(可能是因为混合中的新架构?)。
Searching the link errors on Google, I found advice to explicitly add libstdc++.dylib to the linked libraries. This did not work.
在 Google 上搜索链接错误,我找到了将 libstdc++.dylib 添加到链接库的建议。这没有用。
I experimented by adding libstdc++.6.dylib to the linked libraries instead; this eliminated the link errors, but the app crashed in the standard C++ library code very early.
我尝试将 libstdc++.6.dylib 添加到链接库中;这消除了链接错误,但应用程序很早就在标准 C++ 库代码中崩溃了。
Removing the explicit additions of the library and changing the compiler setting in Build Settings, as noted above, corrected the link errors and runtime problem.
删除库的显式添加并更改构建设置中的编译器设置,如上所述,更正了链接错误和运行时问题。
Thanks to rimestad for the pointer!
感谢 rimestad 的指点!
回答by rimestad
To be honest, I don't like the above answer, as it uses the static lib and not the dynamic!
老实说,我不喜欢上面的答案,因为它使用的是静态库而不是动态库!
I have had the problem myself and found that the problem is that xcode is unable to find any C++ files in you project and thus assumes that the libstc++ is not needed!
我自己也遇到过这个问题,发现问题是 xcode 无法在您的项目中找到任何 C++ 文件,因此假设不需要 libstc++!
Quite annoying when you are linking to a static lib that uses it!!
当您链接到使用它的静态库时非常烦人!!
Solution :
解决方案 :
- Add a empty .mm file to you project!
- Ensure that C++ Standard Libraryis set to libstdc++ (GNU c++ standard library)in the Build Settings
- 向您的项目添加一个空的 .mm 文件!
- 确保在 Build Settings 中将C++ Standard Library设置为libstdc++(GNU c++ 标准库)
This worked for me and I did not have to add -lstdc++ to Other Linker Flags!
这对我有用,我不必将 -lstdc++ 添加到其他链接器标志!
Hope that helps others with the same problem.
希望能帮助其他有同样问题的人。
回答by MarekM
Thanks for your help. I have found solution. I was using -lstdc++ flag in other linker flags but it is not enough now. I had to add "libstdc++.6.0.9.dylib in BuildPhases->Link Binary With Libraries. There was somewhere in the net info that xcode has problems with ios7 stdc++ lib selection and it should be selected manually.
谢谢你的帮助。我找到了解决方案。我在其他链接器标志中使用 -lstdc++ 标志,但现在还不够。我不得不在 BuildPhases->Link Binary With Libraries 中添加“libstdc++.6.0.9.dylib。在网络信息中的某个地方,xcode 在 ios7 stdc++ lib 选择方面存在问题,应该手动选择。
Regards, Marek
问候, 马雷克
回答by wzhang84
I had a similar problem, but @MarekM's answer only solve part of my problem, so I tried to add libstdc++.dylib and libstdc++.6.dylib, and that makes all the compiling error gone.
我有一个类似的问题,但@MarekM 的回答只解决了我的部分问题,所以我尝试添加 libstdc++.dylib 和 libstdc++.6.dylib,这使得所有编译错误都消失了。