Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apple llvm 9.0 can not use flag c++17

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

like image 663
Fausturs Avatar asked Sep 20 '17 09:09

Fausturs


People also ask

How do I run C ++ 17 in Terminal?

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.

Does Apple use LLVM?

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.

What is Apple Clang version?

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.

Does Xcode include LLVM?

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.


1 Answers

-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.

like image 183
ddavis Avatar answered Oct 07 '22 13:10

ddavis