Xcode 提供 -std=c++20 但命令行 clang 不提供
Xcode offers -std=c++20 but command line clang does not
我安装了 Xcode 命令行工具,可以使用 clang++
适用于最高 C++17 的版本。在 Xcode 本身,我可以在构建设置中 select C++20:
但是当我尝试使用带有此选项的命令行中的 clang++
进行编译时:
error: invalid value 'c++20' in '-std=c++20'
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
造成这种不一致的原因是什么?以防万一:
~/ which clang++
/usr/bin/clang++
~/ clang++ -v
Apple clang version 11.0.3 (clang-1103.0.32.29)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
(我也试过clang -x c++
)。
如您所见,Xcode 系统使用不同的命令行工具实例。 Xcode 使用嵌入在 Xcode 的副本,系统将使用位于 Library/Developer/
的副本,不会随 Xcode.[=15= 自动升级]
仅在 Apple Clang
的更高版本中添加了对 c++20
标志的支持,这似乎嵌入在您的 Xcode 中的 clang 确实支持它,但是 [= 中的 clang 安装13=] 没有。
要强制它们是同一版本,您可能需要自己从 https://developer.apple.com/download/all/?q=command%20line%20tools 下载,然后选择与您的 Xcode.
相匹配的版本
我安装了 Xcode 命令行工具,可以使用 clang++
适用于最高 C++17 的版本。在 Xcode 本身,我可以在构建设置中 select C++20:
但是当我尝试使用带有此选项的命令行中的 clang++
进行编译时:
error: invalid value 'c++20' in '-std=c++20'
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
造成这种不一致的原因是什么?以防万一:
~/ which clang++
/usr/bin/clang++
~/ clang++ -v
Apple clang version 11.0.3 (clang-1103.0.32.29)
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
(我也试过clang -x c++
)。
如您所见,Xcode 系统使用不同的命令行工具实例。 Xcode 使用嵌入在 Xcode 的副本,系统将使用位于 Library/Developer/
的副本,不会随 Xcode.[=15= 自动升级]
仅在 Apple Clang
的更高版本中添加了对 c++20
标志的支持,这似乎嵌入在您的 Xcode 中的 clang 确实支持它,但是 [= 中的 clang 安装13=] 没有。
要强制它们是同一版本,您可能需要自己从 https://developer.apple.com/download/all/?q=command%20line%20tools 下载,然后选择与您的 Xcode.
相匹配的版本