86

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?

Xeo
  • 129,499
  • 52
  • 291
  • 397
villintehaspam
  • 8,540
  • 6
  • 45
  • 76
  • Look at the answers [here](http://stackoverflow.com/questions/2946887) and [there](http://stackoverflow.com/questions/3002395). – F'x Jan 01 '11 at 13:57
  • For a more positive outcome, look at: http://stackoverflow.com/questions/837992/update-gcc-on-osx – David Rodríguez - dribeas Jan 01 '11 at 16:24
  • Regarding Clang: I believe it achieved reasonable C++03 support recently, but C++0x is still a far goal. For example, support of variadic template is work in progress and move semantics / rvalue references have not been implemented yet. – Matthieu M. Jan 04 '11 at 15:47
  • Variadic templates work fine for me with clang. – Alexandre Hamez Jan 13 '12 at 10:23

4 Answers4

76

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.

RichardLiu
  • 1,902
  • 1
  • 19
  • 18
  • 2
    @ RichardLiu, what about the `GNU++0X` option for the `C++ Language Dialect` and the `libstdc++` option for `C++ Standard Library`? When do they shall be used? – Tin Jan 22 '12 at 00:30
  • I have had a look in `/Developer/About\ Xcode.pdf` and yes, it says that C++11 is supported, but when I use `-std=gnu++0x` it spits out `cc1plus: error: unrecognized command line option "-std=0x++"`! Should I use `clang++` instead? – errordeveloper Mar 04 '12 at 22:50
  • @errordeveloper, so far I had only successfully compiled C++11 WITHIN Xcode IDE. I don't know how to enable C++11 in command line or makefile. Sorry. – RichardLiu Mar 26 '12 at 07:41
  • 1
    @RichardLiu: XCode normally uses `clang++` when compiling, not `g++`, which is why C++11 support fails when trying to use `g++` from the command line (because the ancient `g++` XCode gives you doesn't support it). Just FYI. – Cornstalks Jan 09 '13 at 05:51
9

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

justin
  • 104,054
  • 14
  • 179
  • 226
1

Xcode uses the GCC or the Clang C++ compilers. Any features supported by those compilers are fair game. GCC's C++ compatibility page is here and the Clang C++ compatibility page is here.

Barry Wark
  • 107,306
  • 24
  • 181
  • 206
0

I've found auto, decltype(), range based "for (:)" work in a cross platform project (LLVM for MacOSX,iOS, gcc/linux, MSVC 10/windows).

lambdas & variadic macros don't appear to work under LLVM yet sadly.

centaurian_slug
  • 3,129
  • 1
  • 17
  • 16
  • 1
    MSVC 10 and 11 don't support range-based for. Clang, on the other hand, *does* support variadic templates just fine. – Alex B Dec 27 '11 at 11:16