在 Mac OS X Snow Leopard 上使用 Xcode 的 C++11
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7543236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C++11 with Xcode on Mac OS X Snow Leopard
提问by nuit9
I have project that is at times developed on Windows/Visual Studio 2010 and uses some C++11 features and I need to be able to develop/build on Mac OS X. When I tried to build the project with Xcode I got a lot of errors around new C++11 features and checked the gcc version to find it's pretty old (4.2). It looks like Apple is trying to force developers to pay an unnecessary upgrade to Lion by refusing to allow Xcode 4+ to be downloaded on any other version of Mac OS thus I'm left with Xcode 3.x.
我的项目有时在 Windows/Visual Studio 2010 上开发并使用一些 C++11 功能,我需要能够在 Mac OS X 上开发/构建。当我尝试使用 Xcode 构建项目时,我得到了很多围绕新的 C++11 特性的错误并检查了 gcc 版本以发现它很旧(4.2)。看起来苹果试图通过拒绝允许在任何其他版本的 Mac OS 上下载 Xcode 4+ 来迫使开发人员为 Lion 支付不必要的升级,因此我只剩下 Xcode 3.x。
How can I continue to use C++11 on Snow Leopard? Is there a way I can do this and keep Xcode as an IDE?
如何在 Snow Leopard 上继续使用 C++11?有什么方法可以做到这一点并将 Xcode 保留为 IDE?
回答by justin
Update feb.25 2012:There are now a lot of features available for you to work with using the latest clang. Maybeyou could target 10.6 if you use language features only. If you need library features, you will need 10.7.
2012 年 2 月 25 日更新:现在有很多功能可供您使用最新的 clang 来使用。如果您只使用语言功能,也许您可以针对 10.6。如果您需要库功能,则需要 10.7。
given the present (sept.24.2011) state of the Xcode toolset, it's easiest (IMO) to choose another ide or os if you need c++11 support.
鉴于 Xcode 工具集的当前(2011 年 9 月 24 日)状态,如果您需要 c++11 支持,最容易(IMO)选择另一个 ide 或 os。
the fork of gcc xcode uses will never support these features. clang is pretty far behind wrt c++11 features (because its c++ implementation is still very new and other compilers have had a few extra years). therefore, the compilers xcode ships with do not presently support enough features for c++11 development, regardless of the version of osx you use.
gcc xcode 使用的分支永远不会支持这些功能。clang 远远落后于 wrt c++11 特性(因为它的 c++ 实现仍然很新,而其他编译器已经有几年了)。因此,无论您使用的 osx 版本如何,xcode 附带的编译器目前都不支持 c++11 开发的足够功能。
you can install a newer version of gcc and use another ide fairly easily.
您可以安装较新版本的 gcc 并相当轻松地使用另一个 ide。
technically, you can also make a plugin for xcode 3 (not officially supported) which invokes another compiler (e.g. a more recent release of gcc). that route has been closed in xc4 (afaik). Updateapparently, it's still available in Xc4; see idljarn's comment below.
从技术上讲,您还可以为 xcode 3(未正式支持)制作一个插件,该插件会调用另一个编译器(例如,最新版本的 gcc)。该路线已在 xc4 (afaik) 中关闭。显然更新了,它在 Xc4 中仍然可用;请参阅下面的 idljarn 评论。
for many projects, it's easier to just use your mac to boot into linux or windows (or use virtualization).
对于许多项目,使用 Mac 启动进入 linux 或 windows(或使用虚拟化)会更容易。
your final option is intel's compiler, which can be used in xcode and provides a decent amount of c++11 support -- try it with xcode before you buy to see if it fits your needs, plays well with xcode, and supports the c++11 features your team uses.
你的最后一个选择是英特尔的编译器,它可以在 xcode 中使用并提供相当数量的 c++11 支持——在你购买之前尝试使用 xcode,看看它是否符合你的需要,与 xcode 配合良好,并支持 c ++11 功能您的团队使用。
lastly, i don't think they do this for your upgrade money. they really don't maintain xcode for multiple releases very well - they just expect you to stay with the latest and greatest unless you need backwards compatibility; you just stop upgrading in that case. they invested in and assisted development of clang after gcc's license changed. so yeah... osx has always been very far behind wrt c++11 support because they decided to switch to another (very young) compiler. if you wait for xcode to support c++11, you will have to wait for clang to support it, which can be quite some time.
最后,我不认为他们这样做是为了你的升级钱。他们真的没有很好地维护多个版本的 xcode——他们只是希望你保持最新和最好的,除非你需要向后兼容;在这种情况下,您只需停止升级即可。在 gcc 的许可证更改后,他们投资并协助开发了 clang。所以是的...... osx 一直远远落后于 wrt c++11 支持,因为他们决定切换到另一个(非常年轻的)编译器。如果你等xcode支持c++11,你就得等clang支持它,这可能需要相当长的时间。
回答by CodingMo
I just saw this now and I would like to update you on this. LLVM currently shipping with XCode is at version 3 (Source). This current version is very good with supporting C++11. Here is a link to what is supported:
我现在才看到这个,我想向你更新这一点。当前随 XCode 一起发布的 LLVM 是第 3 版(源代码)。当前版本非常好,支持 C++11。这是支持的内容的链接:
http://clang.llvm.org/cxx_status.html
http://clang.llvm.org/cxx_status.html
You can compare this with the current GCC support here:
您可以在此处将其与当前的 GCC 支持进行比较:
http://gcc.gnu.org/projects/cxx0x.html
http://gcc.gnu.org/projects/cxx0x.html
As you can see, Clang is currently not far behind, if it is at all, with features of the new standard being supported. The only thing that I see concerning is the lack of support for concurrency features, but that is the case for most C++11 compilers due to the nature of supporting it.So I hope that this answer is not too late and that you are not deterred. Go get the latest version of Xcode and fire away (If you have not done so already ;) )!
如您所见,Clang 目前也不甘落后(如果有的话),支持新标准的功能。我看到的唯一问题是缺乏对并发特性的支持,但由于支持它的性质,大多数 C++11 编译器都是这种情况。所以我希望这个答案还不算太晚,而且你是没有被吓倒。去获取最新版本的 Xcode 并启动(如果您还没有这样做;))!