如何在 Mac 上启用 C++17?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39091173/
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
How to enable C++17 on Mac?
提问by TheBigMalaka
I am able to update gcc on Linux to get -std=c++17 but cannot do the same on Mac. Is there a version of Clang I can update to or some other alternative to get C++17 on my Mac? Please help. Thanks.
我可以在 Linux 上更新 gcc 以获得 -std=c++17 但不能在 Mac 上做同样的事情。是否有我可以更新的 Clang 版本或其他一些替代方法来在我的 Mac 上获得 C++17?请帮忙。谢谢。
回答by halfelf
On my 10.11 El Capitan, Xcode 7.3.1, clang has been updated to:
在我的 10.11 El Capitan,Xcode 7.3.1 上,clang 已更新为:
Apple LLVM version 7.3.0 (clang-703.0.31)
which is almost equivalent to llvm version 3.8. clang++
hasn't -std=c++17
option, but -std=c++1z
, working well at present, though only supporting some features of C++1z.
这几乎相当于 llvm 3.8 版。clang++
没有-std=c++17
选项,但是-std=c++1z
,目前运行良好,虽然只支持 C++1z 的一些特性。
For gcc, you can install a very new one by:
对于 gcc,您可以通过以下方式安装一个非常新的:
brew install gcc --HEAD
which will install gcc-6.1 now, (2016.8). This gcc has limited support for C++17 and can be enabled by -std=c++17
.
现在将安装 gcc-6.1,(2016.8)。这个 gcc 对 C++17 的支持有限,可以通过-std=c++17
.
some update:
一些更新:
The corresponding llvm version of Apple's clang is not clear recently, should be 3.9+ or 4+. Check this wiki pagefor more information.
苹果clang对应的llvm版本最近不清楚,应该是3.9+还是4+。查看此 wiki 页面以获取更多信息。
brew install gcc --HEAD
should always work for mac/homebrew, and give you the cutting edge gnu gcc with many experimental features. On the other hand, normal brew install gcc
should install a gcc supporting most c++17 features now.
brew install gcc --HEAD
应该始终适用于 mac/homebrew,并为您提供具有许多实验性功能的尖端 gnu gcc。另一方面,正常现在brew install gcc
应该安装支持大多数 c++17 功能的 gcc。
For the language standard argument, try -std=c++17
and -std=c++1z
for different compilers, one of them should work.
对于语言标准的说法,尝试-std=c++17
与-std=c++1z
不同的编译器,其中一人应该工作。
回答by DBrown
The v17 standard is now offered by default with Xcode 10, offering both standard, and variant flavors.
v17 标准现在默认随Xcode 10 一起提供,提供标准和变体风格。
via Build Settings:
通过构建设置:
CLANG_CXX_LANGUAGE_STANDARD: C++17/GNU++17
CLANG_CXX_LANGUAGE_STANDARD:C++17/GNU++17
CLI:
命令行界面:
-std=c++17partial support
-std=c++17部分支持
-std=gnu++17
-std=gnu++17
回答by vianney
回答by Galley
Maybe you should install xcode command tool using:
也许您应该使用以下命令安装 xcode 命令工具:
xcode-select --install