When I try some features of c++17, I build my code in command line as follow:
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:
[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
If you want to use -std=c++17 you need to manually install clang. You could do that using brew install llvm (assuming you have homebrew installed). You change the symlinks in usr/bin/clang++ to point at the new destination if you don't want to use the full path to the compiler. This can handle the -std=c++17 flag.
In 2005, Apple Inc. hired Lattner and formed a team to work on the LLVM system for various uses within Apple's development systems. LLVM has been an integral part of Apple's Xcode development tools for macOS and iOS since Xcode 4.
Its contributors include Apple, Microsoft, Google, ARM, Sony, Intel, and AMD. Clang 14, the latest major version of Clang as of March 2022, has full support for all published C++ standards up to C++17, implements most features of C++20, and has initial support for the upcoming C++23 standard. Since v6.
Xcode also includes the LLVM GCC compiler, which uses the GCC compiler front end for maximum compatibility, and the LLVM back end, which takes advantage of LLVM's advanced code generator.
-std=c++17
was 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).
This page https://en.wikipedia.org/wiki/Xcode#Latest_versions appears 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With