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

牧云@^-^@ 提交于 2019-12-19 07:58:28

问题


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?


回答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




回答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++



回答3:


On XCode 5 / opencv 2.4.9, I can select:

And it builds without error. If i set the libc++ without specifying C++ Language Dialect then I get same issue as OP



来源:https://stackoverflow.com/questions/10438253/im-having-some-trouble-with-c11-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!