Compile with c++17 mac
I can't compile with -std=c++17, I got :
error: invalid value 'c++17' in '-std=c++17'
However I update Xcode and clang.
My Clang version is:
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin16.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin`
And I load the newest header like optional, I have to do
#include <experimental/optional>
instead of
#include <optional>
Solution 1:
Xcode brings its own complete toolchain, including headers and the actual compiler.
Apple LLVM version 9.0.0 (clang-900.0.39.2)
(which ships with Xcode 9.2) does not support the usage of the flag -std=c++17
since its too old. The optional header is only included under the folder experimental/
. Which is why you need to #include <experimental/optional>
In order to compile your program with c++17 support using the compiler which comes with Xcode 9.2 you need to use the -std=c++1z
flag.
Xcode 9.3 will be shipped with Apple LLVM version 9.1.0 (clang-902.0.30)
which has support for the -std=c++17
flag. However the optional
header is as of today still under the experimental/
subdirectory. This might change during the betas.
Solution 2:
Here is what I get with this tests:
#include <experimental/optional>
int main(int, char* []) {
return 0;
}
g++ -std=c++17 -o test test.cpp
error: invalid value 'c++17' in '-std=c++17'
g++ -std=c++1z -o test test.cpp
Did you try the c++1z argument? Also of note my test compiles without the -std=c++1z argument provided.
I think I'm on a newer version of OSX than you:
Target: x86_64-apple-darwin17.4.0
Solution 3:
You should use -std=c++1z
as flag.