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

10,094

Solution 1

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

Solution 2

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++
Share:
10,094
Whovian
Author by

Whovian

Updated on June 11, 2022

Comments

  • Whovian
    Whovian almost 2 years

    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?

  • Whovian
    Whovian about 12 years
    I'm really sorry, I'm very new, but how exactly do I do that? Apparently, those are commands for LLVM or something of the sort, but I really don't know what to do.
  • sbooth
    sbooth about 12 years
    If you're not using .xcconfig files you can select your project file in Xcode's inspector and you should see a list of options similar to what Alexander posted.
  • sbooth
    sbooth about 12 years
    Don't forget to select the LLVM compiler also.
  • BergP
    BergP over 10 years
    I have problem with linking std lib. If I choose libc++ (LLVM C++ standard library with C++11 support) then linker cannot link "std::string::find(char, unsigned long) const" and other symbols, if i choose libstc++ (GNU C++ Standart library) then there are compiler errors in headers "cannot find ::std::move" . What am I doing wrong? How can I solve this? Thanks.
  • Rigel Chen
    Rigel Chen about 7 years
    We also need to modify the file name from .m to .mm