Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable C++17 on Mac?

I am able to update gcc on Linux to get -std=c++17 but cannot do the same on Mac. Is there a version of Clang I can update to or some other alternative to get C++17 on my Mac? Please help. Thanks.

like image 795
TheBigMalaka Avatar asked Aug 23 '16 01:08

TheBigMalaka


People also ask

How do I run C ++ 17 on Mac?

For the language standard argument, try -std=c++17 and -std=c++1z for different compilers, one of them should work. Thank you.

Does Xcode support C ++ 17?

To get C++17 support, Xcode 9.3+ is needed, requiring at least macOS 10.13 on the build machine.

How do I run C on Mac?

To run the C program in MacOS we need a code editor and code compiler. The Code editor is used to write source code while the code compiler converts the source code into executable files. To write the source code Microsoft Visual Studio Code is used while to convert it into executable files we use command-line tools.


2 Answers

On my 10.11 El Capitan, Xcode 7.3.1, clang has been updated to:

Apple LLVM version 7.3.0 (clang-703.0.31) 

which is almost equivalent to llvm version 3.8. clang++ hasn't -std=c++17 option, but -std=c++1z, working well at present, though only supporting some features of C++1z.

For gcc, you can install a very new one by:

brew install gcc --HEAD 

which will install gcc-6.1 now, (2016.8). This gcc has limited support for C++17 and can be enabled by -std=c++17.


some update:

The corresponding llvm version of Apple's clang is not clear recently, should be 3.9+ or 4+. Check this wiki page for more information.

brew install gcc --HEAD should always work for mac/homebrew, and give you the cutting edge gnu gcc with many experimental features. On the other hand, normal brew install gcc should install a gcc supporting most c++17 features now.

For the language standard argument, try -std=c++17 and -std=c++1z for different compilers, one of them should work.

like image 169
halfelf Avatar answered Oct 02 '22 12:10

halfelf


The v17 standard is now offered by default with Xcode 10, offering both standard, and variant flavors.

via Build Settings:

CLANG_CXX_LANGUAGE_STANDARD : C++17/GNU++17

CLI:

-std=c++17 partial support

-std=gnu++17

like image 39
DBrown Avatar answered Oct 02 '22 11:10

DBrown