xcode C++11 的 LLVM&Clang 支持
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7981599/
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
LLVM&Clang support of C++11
提问by Kirill Lykov
I have some code written by me for MS VC++10. I use C++11 and, in particular, expressions like
我有一些由我为 MS VC++10 编写的代码。我使用 C++11,特别是像这样的表达式
std::function<int (int)> f =...;
auto it = v.begin();
for_each(it1, it2,[&](int& i) { ++i;});
Now I'm trying out MacOS and XCode with llvm&clang and my code can't be compiled! The question is why? Perhaps, I shall specify an option to use c++11. In this case, where can I fix it in xcode?
现在我正在使用 llvm&clang 尝试 MacOS 和 XCode,但我的代码无法编译!问题是为什么?或许,我应该指定一个使用 c++11 的选项。在这种情况下,我在哪里可以在 xcode 中修复它?
回答by Howard Hinnant
You will need Xcode 4.2.
您将需要 Xcode 4.2。
In your build settings, search for "c++0x" and set the "C++ Language Dialect to C++0x [-std=c++0x]". Then search for "libc++" and set the "C++ Standard Library" to "libc++".
在您的构建设置中,搜索“c++0x”并将“C++ 语言方言设置为 C++0x [-std=c++0x]”。然后搜索“libc++”并将“C++标准库”设置为“libc++”。
Not all C++11 facilities are available. For example lambdas are not yet supported.
并非所有 C++11 工具都可用。例如,尚不支持 lambda。
回答by rubenvb
For a list of C++11 features Clang currently supports, see this nice list. Lambda expressions (and syntactically related initialzer lists) are currently not implemented.
有关 Clang 当前支持的 C++11 功能列表,请参阅这个不错的列表。Lambda 表达式(以及与语法相关的初始值设定项列表)目前尚未实现。
Your only choice for now (until Clang devs implement lambda support) is using MacPorts' GCC 4.5/4.6 compilers.
您现在唯一的选择(直到 Clang 开发人员实现 lambda 支持)是使用 MacPorts 的 GCC 4.5/4.6 编译器。
The extra command-line option would be -std=c++0x
(in the next version of Clang and GCC it will be the proper -std=c++11
).
额外的命令行选项将是-std=c++0x
(在 Clang 和 GCC 的下一版本中,它将是正确的-std=c++11
)。