我在 Xcode 中使用 C++11 时遇到了一些问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10438253/
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
I'm having some trouble with C++11 in Xcode
提问by Whovian
I'm a Mac OS X Lion user who uses Xcode for C++, and it appears that no updates are available for Xcode. I do not appear to be able to compile C++11-exclusive code, but for whatever reason, I thought Apple had gotten C++11 pretty much implemented. And yes, I do have support for Command Line Tools.
我是 Mac OS X Lion 用户,将 Xcode 用于 C++,而且 Xcode 似乎没有可用的更新。我似乎无法编译 C++11 独有的代码,但无论出于何种原因,我认为 Apple 已经完全实现了 C++11。是的,我确实支持命令行工具。
Then again, that might just be me. If so, is there any sort of IDE that supports C++11, or any way to upgrade?
再说一次,那可能只是我。如果是这样,是否有任何类型的 IDE 支持 C++11,或者有什么升级方式?
回答by Aligus
I use Xcode and set the following settings:
我使用 Xcode 并设置以下设置:
C++ language dialect: C++11 or GNU++11
C++ 语言方言:C++11 或 GNU++11
C++ Standart Library: libc++ (LLVM C++ standart library with C++11 support)
C++ 标准库:libc++(支持 C++11 的 LLVM C++ 标准库)
Xcode version: 4.3.2
Xcode 版本:4.3.2
回答by sbooth
If you're using Xcode 4.3 there are several relevant project settings you need to use C++11 features. The first is to use the clang compiler. Something like
如果您使用的是 Xcode 4.3,则需要使用几个相关的项目设置才能使用 C++11 功能。首先是使用clang编译器。就像是
GCC_VERSION = com.apple.compilers.llvm.clang.1_0
in your .xcconfig
will set it, or you can use the GUI.
在您的.xcconfig
意愿中设置它,或者您可以使用 GUI。
Next, you need to tell LLVM which C++ standard to use:
接下来,您需要告诉 LLVM 使用哪个 C++ 标准:
CLANG_CXX_LANGUAGE_STANDARD = gnu++11
This will make language features like range based for, delegated constructors, etc. available.
这将使诸如基于范围、委托构造函数等语言功能可用。
Finally, if you want to use C++11 STL features (such as std::unordered_map
) you need to use the libc++ STL:
最后,如果您想使用 C++11 STL 特性(例如std::unordered_map
),您需要使用 libc++ STL:
CLANG_CXX_LIBRARY = libc++
回答by Elliot Woods
On XCode 5 / opencv 2.4.9, I can select:
在 XCode 5 / opencv 2.4.9 上,我可以选择:
And it builds without error. If i set the libc++ without specifying C++ Language Dialect then I get same issue as OP
它构建没有错误。如果我设置 libc++ 而不指定 C++ 语言方言,那么我会遇到与 OP 相同的问题