Compile with c++17 mac
Asked Answered
C

5

8

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>
Caboodle answered 25/1, 2018 at 14:25 Comment(5)
Try -std=c++17 or -std=c++1zGastrotomy
@manni66 Sorry it's a typo, I correctedCaboodle
What is your question?Reporter
@n.m. How can I compile with -std=c++17Caboodle
Apple ships a compiler that's too old to support this flag. You probably need to switch to a version of llvm/clang not provided by Apple.Reporter
C
8

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.

Catnap answered 3/2, 2018 at 16:56 Comment(0)
C
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
Coat answered 25/1, 2018 at 14:29 Comment(1)
Yes but i can't write include experimental/optional I need to include just optional, but with c++1z i can compile, I will update thenCaboodle
H
1

You should use -std=c++1z as flag.

Heliport answered 25/1, 2018 at 14:30 Comment(0)
A
0

libc++ with c++17 support since macos 15

Afferent answered 27/5, 2020 at 4:25 Comment(0)
S
0

-std=c++1z also works on Apple LLVM version 8.1.0 (clang-802.0.42)

Strophanthus answered 11/1, 2022 at 6:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.