xcode 苹果 llvm 9.0 不能使用标志 c++17

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/46318742/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:15:42  来源:igfitidea点击:

apple llvm 9.0 can not use flag c++17

xcodellvmc++17clang++

提问by Fausturs

When I try some features of c++17, I build my code in command line as follow:

当我尝试 c++17 的一些功能时,我在命令行中构建我的代码如下:

llvm-g++ -std=c++17 main.cpp 

but it failed. I got:

但它失败了。我有:

error: invalid value 'c++17' in '-std=c++17'

the version of my llvm-g++ is:

我的 llvm-g++ 的版本是:

[wjy@wjy-mba] cpp$ llvm-g++ -v
Apple LLVM version 9.0.0 (clang-900.0.37)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

and at the same time, I can build my code in Xcode (with c++17). Xcode setting

同时,我可以在 Xcode(使用 c++17)中构建我的代码。 Xcode 设置

回答by ddavis

-std=c++17was added in Clang 5.0.0 (released very recently - earlier this month - see http://releases.llvm.org/5.0.0/tools/clang/docs/ReleaseNotes.html).

-std=c++17已添加到 Clang 5.0.0(最近发布 - 本月初 - 参见http://releases.llvm.org/5.0.0/tools/clang/docs/ReleaseNotes.html)。

This page https://en.wikipedia.org/wiki/Xcode#Latest_versionsappears to believe Xcode 9.0 is still using the LLVM/Clang 4.0 release. This is in agreement with the error you're running into.

此页面https://en.wikipedia.org/wiki/Xcode#Latest_versions似乎相信 Xcode 9.0 仍在使用 LLVM/Clang 4.0 版本。这与您遇到的错误一致。

回答by MCCCS

Apple-LLVM 10 that comes with Xcode 10 supports C++17 and C++20 draft:

Xcode 10 自带的 Apple-LLVM 10 支持 C++17 和 C++20 草案:

note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU
      extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions'
      standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions'
      standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions'
      standard
note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions'
      standard

回答by Lambo

I believe you are looking for the flag -std=c++1z

我相信您正在寻找标志 -std=c++1z