Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm having some trouble with C++11 in Xcode

I'm a Mac OS X Lion user who uses Xcode for C++, and it appears that no updates are available for Xcode. I do not appear to be able to compile C++11-exclusive code, but for whatever reason, I thought Apple had gotten C++11 pretty much implemented. And yes, I do have support for Command Line Tools.

Then again, that might just be me. If so, is there any sort of IDE that supports C++11, or any way to upgrade?

like image 802
Whovian Avatar asked May 03 '12 19:05

Whovian


2 Answers

I use Xcode and set the following settings:

C++ language dialect: C++11 or GNU++11

C++ Standart Library: libc++ (LLVM C++ standart library with C++11 support)

Xcode version: 4.3.2

XCode project settings

like image 79
Aligus Avatar answered Sep 28 '22 06:09

Aligus


If you're using Xcode 4.3 there are several relevant project settings you need to use C++11 features. The first is to use the clang compiler. Something like

GCC_VERSION = com.apple.compilers.llvm.clang.1_0

in your .xcconfig will set it, or you can use the GUI.

Next, you need to tell LLVM which C++ standard to use:

CLANG_CXX_LANGUAGE_STANDARD = gnu++11

This will make language features like range based for, delegated constructors, etc. available.

Finally, if you want to use C++11 STL features (such as std::unordered_map) you need to use the libc++ STL:

CLANG_CXX_LIBRARY = libc++
like image 36
sbooth Avatar answered Sep 28 '22 07:09

sbooth