I'm having some trouble with C++11 in Xcode
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
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++
Whovian
Updated on June 11, 2022Comments
-
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 about 12 yearsI'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 about 12 yearsIf 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 about 12 yearsDon't forget to select the LLVM compiler also.
-
BergP over 10 yearsI 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 about 7 yearsWe also need to modify the file name from .m to .mm