Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use C++11 with Xcode?

I am considering the use of some C++11 features (like auto for instance) in some cross-platform projects (Windows+Mac). On Windows, Visual Studio supports parts of the upcoming C++11 standard that would allow me to simplify parts of the code base so naturally I would be interested in starting to use these features.

But as far as I am aware, the current XCode version (3.2.4 + GCC 4.2) does not support any C++11 features at all. Can I upgrade the GCC version or the CLang version somehow? Or should I just bite my tongue and wait for Apple to package a new version sometime in the future?

like image 836
villintehaspam Avatar asked Jan 01 '11 13:01

villintehaspam


People also ask

What version of C does XCode use?

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.

Can you use C in XCode?

Great, now that Xcode is installed, you have two options for developing and running C programs on your Mac. The first option involves using Xcode as an editor only to write your source code, and using the "gcc" command within the Terminal window to compile your code.

Does my compiler support C++11?

To see if your compiler has C++11 support, run it with just the --version option to get a print out of the version number. Do this for whichever compiler(s) you wish to use with Rosetta. Acceptable versions: GCC/g++: Version 4.8 or later.


2 Answers

Xcode 4.2 had finally added support for C++0X:

  1. In the project build settings screen, switch on "All" options.

  2. In the "Build Options" section, set compiler to "Apple LLVM compiler 3.0".

  3. Scroll down to "Apple LLVM Compiler 3.0 - Language" section and set "C++ Language Dialect" to "C++0X" and "C++ Standard Library" to "libc++".

The std::move(), move constructor and R-Value reference are known to work as expected, and I'm testing on the std::thread and std::atomic.

like image 130
RichardLiu Avatar answered Oct 11 '22 23:10

RichardLiu


======= Update 2012: =======

Start with Clang - Many C++11 features are now available in Clang. It's included with Xcode.

======= Original answer from Jan 2011: =======

intel's compiler may be the cleanest way to go at this time. http://software.intel.com/en-us/articles/intel-composer-xe/

clang's promising, but not particularly stable or featured wrt c++0x features. c++ is still very new for clang.

gcc: relatively mature, but you'll have to write and maintain your compiler plugins for xcode.

you can also specify custom scripts, but that is a pain to maintain... unless you go all out and create an adaptor tool.

like image 39
justin Avatar answered Oct 11 '22 23:10

justin