在 Ubuntu 上安装 C++11 编译器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8403722/
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
Installing C++11 compiler on Ubuntu?
提问by tsaarni
What is the simplest way to get most up-to-date C++11 compiler on Ubuntu 11.04 without breaking the existing compiler from the distribution. I'd prefer pre-built package instead of compiling whole toolchain myself.
在 Ubuntu 11.04 上获得最新的 C++11 编译器而不破坏发行版中现有编译器的最简单方法是什么。我更喜欢预先构建的包,而不是自己编译整个工具链。
采纳答案by Warren P
Update in 2017: It seem GCC 7 and higher has full C++ 2011 compliance. The rest of the answer below was written in the GCC 4.7 era, and was correct when written in 2011.
2017 年更新:似乎 GCC 7 及更高版本完全符合 C++ 2011。下面的其余答案是在 GCC 4.7 时代写的,在 2011 年写的时候是正确的。
Strictly speaking, I can not offer you any 100% C++ 2011 compliant open source compiler, because there aren't any that are 100% there yet.
严格来说,我无法为您提供任何 100% 兼容 C++ 2011 的开源编译器,因为目前还没有任何 100% 兼容的开源编译器。
It looks like you should stay with GCC for now, and GCC 4.6 binaries are included in recent Ubuntu distributions. C++ 2011 is incomplete in GCC 4.6 but contains a lot of 2011 stuff, more than Clang+llvm. It's more than 90% C++ 2011 feature complete. GCC 4.7 contains yet more stuff, but I don't see gcc-4.7 binary packages in Ubuntu 11.x yet, but you can check over herefor another way to get gcc 4.7 binaries on ubuntu, or try AskUbuntu, a stackexchange powered site for ubuntu.
看起来您现在应该继续使用 GCC,并且 GCC 4.6 二进制文件包含在最近的 Ubuntu 发行版中。C++ 2011 在 GCC 4.6 中是不完整的,但包含了很多 2011 的东西,比 Clang+llvm 还多。它已完成 90% 以上的 C++ 2011 功能。GCC 4.7 包含更多内容,但我还没有在 Ubuntu 11.x 中看到 gcc-4.7 二进制包,但是您可以在此处查看另一种在 ubuntu 上获取 gcc 4.7 二进制文件的方法,或者尝试AskUbuntu,一个由stackexchange提供支持的站点对于 ubuntu。
According to this pageClang+llvm does not yet offer full C++ 2011 standards compliance, either, and I haven't done the exact math but I see a lot more "No" entries on Clang, versus Gcc.
根据这个页面,Clang+llvm 也没有提供完整的 C++ 2011 标准合规性,我还没有做确切的数学计算,但我看到更多关于 Clang 的“否”条目,而不是 Gcc。
回答by Hauleth
GCC 4.6 provides most of the C++11 features. One has only to add the flag -std=c++0x
and can use range based for
loops, strong enums, UTF strings, etc. For the list of features available in a given version of GCC one can check on http://gcc.gnu.org/projects/cxx0x.html.
GCC 4.6 提供了大部分 C++11 特性。只需添加标志-std=c++0x
,即可使用基于范围的for
循环、强枚举、UTF 字符串等。对于给定 GCC 版本中可用的功能列表,可以查看http://gcc.gnu.org/projects/ cxx0x.html。