Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 927
Max0u Avatar asked Jan 25 '18 14:01

Max0u


1 Answers

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.

like image 168
p0fi Avatar answered Oct 19 '22 04:10

p0fi