我可以在 XCode 4 或 OSX Lion 中使用 C++11 的最新功能吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7482026/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:58:54  来源:igfitidea点击:

Can i use the latest features of C++11 in XCode 4 or OSX Lion?

c++xcodec++11g++clang

提问by Per Arneng

Possible Duplicate:
Can I use C++11 with Xcode?

可能的重复:
我可以在 Xcode 中使用 C++11 吗?

It seems like xcode 4 contains older versions of clang and gcc. Can i uppgrade gcc or clang and use them with xcode 4? I would like to use gcc >= 4.6 or the latest clang.

似乎 xcode 4 包含旧版本的 clang 和 gcc。我可以升级 gcc 或 clang 并将它们与 xcode 4 一起使用吗?我想使用 gcc >= 4.6 或最新的 clang。

My main goal is to be able to have as much of the new features from C++11 available when programming C++ on mac osx lion so ditching xcode is also an option if that is needed.

我的主要目标是在 mac osx lion 上编程 C++ 时,能够拥有尽可能多的来自 C++11 的新功能,因此如果需要,放弃 xcode 也是一种选择。

What are my options to achieve this?

我有哪些选择来实现这一目标?

采纳答案by bames53

The version of clang in Xcode 4.1 does support some C++11 features, including variadic templates and rvalue references. Also libc++, an implementation of the C++11 standard library is included in Lion.

Xcode 4.1 中的 clang 版本确实支持一些 C++11 功能,包括可变参数模板和右值引用。此外,Lion 中还包含 libc++,这是 C++11 标准库的实现。

See my answer to Osx Lion: Xcode 4.1 how do I setup a c++0x projectfor details on setting this up.

请参阅我对Osx Lion 的回答:Xcode 4.1 how do I setup a c++0x project了解有关设置的详细信息。

回答by Chris Lattner

Each version of Xcode 4 adds new compiler support features. Please try Xcode 4.2 when it comes out.

Xcode 4 的每个版本都添加了新的编译器支持功能。请在 Xcode 4.2 出来后试用。

回答by John Bowers

I recently spent a bit of time installing Macports GCC 4.6 and modifying some Xcode compiler templates so I could select and use it from my Xcode projects. I did eventually get it working, the main drawback was that GCC 4.6 doesn't know what to do with "blocks". If you are planning on doing any COCOA, GUI stuff then this probably isn't a good option for you (as a bunch of the NS Object header files contain blocks, you get stopped pretty early).

我最近花了一些时间安装 Macports GCC 4.6 并修改了一些 Xcode 编译器模板,以便我可以从我的 Xcode 项目中选择和使用它。我最终让它工作了,主要的缺点是 GCC 4.6 不知道如何处理“块”。如果你打算做任何可可、GUI 的东西,那么这对你来说可能不是一个好的选择(因为一堆 NS 对象头文件包含块,你很早就停止了)。

If you are doing any other kind of project you can probably get it to work with this method.

如果您正在做任何其他类型的项目,您可能可以使用这种方法来使用它。

You can even get it to create universal binaries with some creativity. I have all the gory details on how I accomplished this here:

您甚至可以使用它来创建具有一些创造力的通用二进制文件。我在这里有关于我如何做到这一点的所有血腥细节:

http://thecoderslife.blogspot.com/2015/07/building-with-gcc-46-and-xcode-4.html

http://thecoderslife.blogspot.com/2015/07/building-with-gcc-46-and-xcode-4.html

回答by Jeff Diamond

Turns out that XCode 4.2.0 (the latest version compatible with Snow Leopard) only comes with CLANG 2.0, so no C++ '11 stuff. (Even XCode 4.2.1 still uses CLANG 2.0, so it seems like you need at least XCode 4.2.3 and Lion to use any C++ '11.

事实证明,XCode 4.2.0(与雪豹兼容的最新版本)只带有 CLANG 2.0,所以没有 C++ '11 的东西。(即使 XCode 4.2.1 仍然使用 CLANG 2.0,因此您似乎至少需要 XCode 4.2.3 和 Lion 才能使用任何 C++ '11。

回答by will

Consider using Clang++ with libc++ http://libcxx.llvm.org/

考虑在 libc++ http://libcxx.llvm.org/ 中使用 Clang++

It supports Mac OS X and has about 98% C++0x features finished except atomics.

它支持 Mac OS X,并且除了原子之外完成了大约 98% 的 C++0x 功能。

回答by rubenvb

Macports provides GCC 4.6, but any GCC version >= 4.2.1 (ie the latest official Apple GCC) cannot create universal binaries (32 and 64-bit code in one file) directly. There may be other drawbacks, but otherwise this should work for you.

Macports 提供 GCC 4.6,但任何 GCC 版本 >= 4.2.1(即最新的官方 Apple GCC)都不能直接创建通用二进制文件(32 位和 64 位代码在一个文件中)。可能还有其他缺点,但除此之外这应该对您有用。