简体   繁体   English

Xcode 提供 -std=c++20 但命令行 clang 不提供

[英]Xcode offers -std=c++20 but command line clang does not

I have the Xcode command line tools installed and can use clang++ fine for versions up to C++17.我已经安装了 Xcode 命令行工具,并且可以在 C++17 之前的版本中使用clang++ In Xcode itself, I can select C++20 in the build settings:在 Xcode 本身中,我可以在构建设置中 select C++20 :

在此处输入图像描述

But when I try to compile using clang++ from the command line with this option:但是当我尝试从命令行使用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

What would be the reason for this inconsistency?这种不一致的原因是什么? In case it matters:万一这很重要:

~/ 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

(I also tried clang -x c++ ). (我也试过clang -x c++ )。

Like you have noticed, Xcode and system uses different instance of Command Line Tools.如您所见,Xcode 和系统使用不同的命令行工具实例。 Xcode uses the one that is embedded in Xcode, and the system will use a copy located in Library/Developer/ , which is not automatically upgraded along with Xcode. Xcode 使用的是嵌入在 Xcode 中的那个,系统将使用一个位于Library/Developer/中的副本,它不会随 ZA3B5EBD8A1E9EBF44A172E80D5A7D3A 一起自动升级。

Support of c++20 flag is only added for later versions of Apple Clang , which seems like the clang embedded within your Xcode does support it, but the clang install in Library/Developer does not. Support of c++20 flag is only added for later versions of Apple Clang , which seems like the clang embedded within your Xcode does support it, but the clang install in Library/Developer does not.

To force them be the same version, you might need to download it yourself from https://developer.apple.com/download/all/?q=command%20line%20tools , and choose the version that matches your Xcode.要强制它们是相同的版本,您可能需要自己从https://developer.apple.com/download/all/?q=command%20line%20tools下载它,然后选择与您的 Xcode 匹配的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM