I have the Xcode command line tools installed and can use clang
fine for versions up to C 17. In Xcode itself, I can select C 20 in the build settings:
But when I try to compile using clang
from the command line with this option:
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
).
CodePudding user response:
Like you have noticed, Xcode and system uses different instance of Command Line Tools. 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.
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 line tools, and choose the version that matches your Xcode.