xcode C++11 在 Mac 上使用 Clang 或 GCC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13958197/
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 on Mac with Clang or GCC
提问by Guillaume
I have Xcode 4.5.2 on Moutain Lion, and I have install the lastest "Command Line Tools" but when I tried to compile with g++
or clang++
(and the options -std=c++11 -stdlib=libc++
) I get an error.
With g++
:
我在 Moutain Lion 上安装了 Xcode 4.5.2,并且安装了最新的“命令行工具”,但是当我尝试使用g++
or clang++
(和选项-std=c++11 -stdlib=libc++
)进行编译时出现错误。与g++
:
cc1plus: error: unrecognized command line option "-std=c++11"
cc1plus: error: unrecognized command line option "-stdlib=libc++"
With clang++
:
与clang++
:
clang: error: invalid deployment target for -stdlib=libc++ (requires OS X 10.7 or later)
It's in a Qt project.
它在一个 Qt 项目中。
So how can I used the C++11 on my Mac ?
那么如何在我的 Mac 上使用 C++11 呢?
采纳答案by Marshall Clow
As you found, g++ does not support those command line options.
如您所见,g++ 不支持这些命令行选项。
It sounds like you're using Xcode.
听起来您正在使用 Xcode。
For clang, you should look at the project settings, and make sure that the "Deployment Target" is set to 10.7 (or 10.8)
对于 clang,您应该查看项目设置,并确保“部署目标”设置为 10.7(或 10.8)
What the error message is telling you is that libc++ is not available for 10.6 and before.
错误消息告诉您的是 libc++ 不适用于 10.6 及更早版本。
回答by Thilo
I installed gcc-4.7 on my Mac to make C++11 work. GCC in its current version is fairly good at supporting C++11, so this should be a fair choice.
我在 Mac 上安装了 gcc-4.7 以使 C++11 工作。当前版本的 GCC 在支持 C++11 方面相当不错,所以这应该是一个公平的选择。
The installation can be done by Homebrewand is not that complicated (at least I was able to do it...)
安装可以通过Homebrew完成,并没有那么复杂(至少我能够做到......)
To install Homebrew if you do not already have it:
如果您还没有 Homebrew,要安装它:
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
Now run
现在运行
brew doctor
and fix whatever problems come up (there is something written in the hombrew documentation for that). Finally, install current gcc:
并解决出现的任何问题(在 hombrew 文档中为此写了一些内容)。最后,安装当前的 gcc:
brew install gcc
If everything goes well you should be able to access g++-4.7
, which allows -std=c++0x
.
如果一切顺利,您应该能够访问g++-4.7
,这允许-std=c++0x
.
回答by Thilo
Try -std=c++0x
if c++11
doesn't work. Support for the -std=c++11
option is relatively new in GCC and you might not have a recent enough version.
尝试-std=c++0x
,如果c++11
不工作。-std=c++11
GCC 中对该选项的支持相对较新,您可能没有足够新的版本。
I'd trust Marshall on the libc++ issue.
在 libc++ 问题上,我相信 Marshall。