Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 on Mac with Clang or GCC

I have Xcode 4.5.2 on Moutain Lion, and I have install the lastest "Command Line Tools" but when I tried to compile with g++ or clang++ (and the options -std=c++11 -stdlib=libc++) I get an error. With g++:

cc1plus: error: unrecognized command line option "-std=c++11"
cc1plus: error: unrecognized command line option "-stdlib=libc++" 

With clang++:

clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)

It's in a Qt project.

So how can I used the C++11 on my Mac ?

like image 432
Guillaume Avatar asked Dec 19 '12 17:12

Guillaume


People also ask

Should I use GCC or clang?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

Does Apple use Clang or GCC?

Apple ships the clang/LLVM compiler with macOS. Clang is a "front-end" that can parse C , C++ and Objective-C down to something that LLVM (referred to as a "back-end") can compile. Clang/LLVM is located in /Applications/Xcode. app/somewhere.

Does clang support c11?

C++11 implementation statusYou can use Clang in C++11 mode with the -std=c++11 option. Clang's C++11 mode can be used with libc++ or with gcc's libstdc++.

Does Xcode use GCC or clang?

Xcode 4.6. 2 uses the Clang C++ compiler frontend with LLVM as backend which is conform to the C++11 standart and uses libc++ as the standart library.


1 Answers

As you found, g++ does not support those command line options.

It sounds like you're using Xcode.

For clang, you should look at the project settings, and make sure that the "Deployment Target" is set to 10.7 (or 10.8)

What the error message is telling you is that libc++ is not available for 10.6 and before.

like image 79
Marshall Clow Avatar answered Oct 02 '22 14:10

Marshall Clow