我可以在 Xcode 中使用 C + + 11吗?

我正在考虑在一些跨平台项目(Windows + Mac)中使用一些 C + + 11特性(例如 auto)。在 Windows 上,Visual Studio 支持即将推出的 C + + 11标准的一部分,这些标准允许我简化代码库的一部分,因此我自然会对开始使用这些特性感兴趣。

但据我所知,目前的 XCode 版本(3.2.4 + GCC 4.2)根本不支持任何 C + + 11特性。我可以升级海湾合作委员会版本或 CLang 版本以某种方式?或者我应该咬紧舌头,等待苹果在未来某个时候推出新版本?

77601 次浏览

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.

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

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.

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.