Windows 上的 C++11
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18212873/
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 Windows
提问by Sh4pe
I'm wondering how well writing software in C++11 works on Windows yet. It would be most comfortable (and propably most natural) to use one of the native compilers for Windows - I'm thinking about Visual Studio 2012 Express or Visual Studio 2013 Express here. Everything I could find so far on that matter is
我想知道在 Windows 上用 C++11 编写软件的效果如何。使用 Windows 的本机编译器之一将是最舒服的(并且可能是最自然的) - 我在这里考虑的是 Visual Studio 2012 Express 或 Visual Studio 2013 Express。到目前为止我能找到的关于这件事的一切都是
- http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx(Comparison of C++11 features of VC10 and VC11, which seems to be quite bad)
- http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-breaking-changes-in-vs-2013.aspx(not really transparent, didn't give me a good idea how well it works)
- http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx(VC10和 VC11 的 C++11 特性对比,貌似挺烂的)
- http://blogs.msdn.com/b/vcblog/archive/2013/06/28/c-11-14-stl-features-fixes-and-break-changes-in-vs-2013.aspx(不是真的透明,并没有让我知道它的效果如何)
Does anyone have any experience how well the current Visual Studio versions can handle C++11? I really want to start using auto, lambdas, variadic templates, template aliases, initializer lists and rvalue references (to name just a few) and all the other good stuff right now, but if Windows might be a problem I might have to use C++03 further.
有没有人知道当前的 Visual Studio 版本可以处理 C++11 的程度如何?我现在真的很想开始使用 auto、lambdas、可变参数模板、模板别名、初始化列表和右值引用(仅举几例)以及所有其他好东西,但如果 Windows 可能是一个问题,我可能不得不使用 C ++03 进一步。
Another possibility seems to be to install LLVM and Clang on Windows. My primary platform is OSX, and on that system Clang's support for C++11 is really good. But I read that the LLVM-version of the standard library for C++ (libc++) does not work well on Windows. So LLVM/clang might not be an option.
另一种可能性似乎是在 Windows 上安装 LLVM 和 Clang。我的主要平台是 OSX,在该系统上 Clang 对 C++11 的支持非常好。但是我读到 C++ (libc++) 标准库的 LLVM 版本在 Windows 上运行不佳。所以 LLVM/clang 可能不是一个选择。
What are your opinions on C++11 development on Windows?
您对 Windows 上的 C++11 开发有何看法?
Thank you!
谢谢!
回答by
I can only give you my experience as a developer, as I've been building against the cutting edge of C++ on Windows using Visual C++ for just about everything, while also installing several other compilers and IDEs (including building Clang myself on Windows for Visual Studio 2012, 2012 CTP, and 2013 Preview). The following is my experience up until right now (August 13th, 2013), and is based on Herb Sutter's talkand working with the compiler every day.
我只能向您提供我作为开发人员的经验,因为我一直在使用 Visual C++ 在 Windows 上针对 C++ 的最前沿进行构建,同时还安装了其他几个编译器和 IDE(包括自己在 Windows 上构建 Clang for Visual Studio 2012、2012 CTP 和 2013 预览版)。以下是我截至目前(2013 年 8 月 13 日)的经验,基于Herb Sutter 的谈话和每天与编译器的合作。
The Quick
快速
Run in the opposite direction of Visual Studio / VC++. Support for C++11 is slow, and they're currently being crushed in terms of compiler features versus Clang and GCC.
在 Visual Studio/VC++ 的相反方向运行。对 C++11 的支持很慢,而且与 Clang 和 GCC 相比,它们目前在编译器功能方面被压垮了。
The Present
当下
Visual C++'s C++11 (and C++14 support) is beyond abysmal right now. They lack powerful features that make template metaprogramming in C++ great (using
expressions in particular).
Visual C++ 的 C++11(和 C++14 支持)现在非常糟糕。它们缺乏使 C++ 中的模板元编程变得出色的强大功能(using
尤其是表达式)。
Using doesn't exist right now. I have spent hours and hours porting great C++11 code with
using
to VC++, only to have it break it certain places, snap, or just become near damn unmaintainable.Variadic support in the CTP was horrifically terrible, and while it got better for Visual Studio 2013 Preview's version of the compiler, it's still fairly bad at complex variadic and template expressions that obey the standard (and compile fine in GCC and Clang).
=delete
and=default
are pretty much gone from VC++ right now; in the hopeful near future, maybe it will work out (and it should come "soon-ish", according to the roadmap) (I had to implement r-value constructors explicitly for many simple classes all the way down a 8-class inheritance hierarchy once. It was the worst slap in the face, when I watched GCC and Clang users get all of my explicit hardcoded work for free with=default
).As a holdover (primarily because of Windows OS code and some binary compatabilities), Empty-Base-Class-Optomizations in VC++ don't work. Don't expect your class hierarchy sizes or member layout to be optimized in the least (watch your ordering in
std::tuple
when packing variable types).
使用现在不存在。我花了好几个小时将出色的 C++11 代码移植
using
到 VC++,结果却让它在某些地方中断、崩溃,或者变得几乎无法维护。CTP 中的可变参数支持非常糟糕,虽然它在 Visual Studio 2013 Preview 的编译器版本中变得更好,但在遵守标准的复杂可变参数和模板表达式(并在 GCC 和 Clang 中编译得很好)方面仍然相当糟糕。
=delete
并且=default
现在几乎从 VC++ 消失了;在充满希望的不久的将来,也许它会成功(根据路线图,它应该“很快”到来)(我必须为许多简单的类明确实现 r 值构造函数,一直到 8 类继承一次。这是最糟糕的一记耳光,当我看到 GCC 和 Clang 用户免费获得我所有明确的硬编码工作时=default
)。作为保留(主要是因为 Windows 操作系统代码和一些二进制兼容性),VC++ 中的 Empty-Base-Class-Optomizations 不起作用。不要期望您的类层次结构大小或成员布局至少得到优化(在
std::tuple
打包变量类型时注意您的排序)。
This is about all the frustrations I've come into contact with so far. They're work-aroundable -- I have to work with them every day -- but if you want great C++ support, you should jump for GCC or Clang and somehow make it work on your machine.
这就是我迄今为止接触到的所有挫折。它们是可以解决的——我必须每天和他们一起工作——但是如果你想要很好的 C++ 支持,你应该跳到 GCC 或 Clang 并以某种方式让它在你的机器上工作。
The Future
未来
If you really want C++11, you will need to wait about a year, and even then Visual Studio 2013's release of VC++ will still be missing a few features (and don't expect them to be bugless either). VC++ for 2013 will also still be critically missing std::move and explicit r-value support in many places, making it painful when you expect things to work.
如果你真的想要 C++11,你将需要等待大约一年,即使这样,Visual Studio 2013 的 VC++ 版本仍然会缺少一些功能(也不要指望它们没有错误)。2013 年的 VC++ 也将在许多地方严重缺少 std::move 和显式 r 值支持,当您期望事情正常时会很痛苦。
The Caveat
警告
If you're not a powerful Vim user, you're low on options when it comes to IDEs that you can work with (that play nice with GDB/GCC or Clang).
如果您不是一个强大的 Vim 用户,那么当涉及到您可以使用的 IDE(与 GDB/GCC 或 Clang 配合得很好)时,您的选择很少。
- QtCreator is nice, works with MinGW, and is generally fully featured enough to get work done.
- Sublime Text can be used, but you'll have to write your own building system or delegate that to something else.
- Code::Blocks's autocomplete is wonky and behaves strangely, and the IDE itself feels clunky.
- Eclipse is supposed to be good, but my experiences with it are clunky and strange, with odd input lags at time (despite a 8.00 GB i7 Haswell machine using an SSD).
- Visual Studio, as an IDE, is pretty solid. Then stack Visual Assist X on top, and it works pretty damn well for C++ coding. It's really the only reason I continue to stick with it, but I've already made headway into learning Vim so I can mostly ditch Visual Studio altogether, when the time comes.
- QtCreator 很好,可与 MinGW 配合使用,并且通常功能齐全,足以完成工作。
- 可以使用 Sublime Text,但您必须编写自己的构建系统或将其委托给其他东西。
- Code::Blocks 的自动完成功能很不稳定,行为也很奇怪,IDE 本身也感觉很笨拙。
- Eclipse 应该是好的,但我对它的体验既笨拙又奇怪,有时输入会出现奇怪的延迟(尽管使用 SSD 的 8.00 GB i7 Haswell 机器)。
- Visual Studio 作为 IDE,非常可靠。然后将 Visual Assist X 堆叠在顶部,它对于 C++ 编码非常有效。这确实是我继续坚持使用它的唯一原因,但我已经在学习 Vim 方面取得了进展,所以当时机成熟时,我几乎可以完全放弃 Visual Studio。
About Libraries
关于图书馆
Library support in VC++ is pretty complete (for as much as their broken compiler lets them be complete). It has regex, while most other libraries have non-existent or broken regex support. But that doesn't mean that the VC++ library plays nice with some C++11 features that it says it does(picture by melak47).
VC++ 中的库支持非常完整(因为它们损坏的编译器让它们变得完整)。它有正则表达式,而大多数其他库不存在或破坏了正则表达式支持。但这并不意味着 VC++库与它所说的某些 C++11 功能配合得很好(图片来自melak47)。
And Lastly
最后
If you want code that you know is going to work in Windows, 100%, for the rest of eternity, you'll probably want to program against VC++. The other "benefit" is that the code you write in VC++ is the smallest subset of C++/C++11 you can write with, so in the end it should compile everywhere. Of course, that goes against the very idea of using beautiful C++11 and enjoying it, so... pick your poison(s) wisely.
如果您希望代码能够在 Windows 中 100% 运行,并且在永恒的余下时间里都可以运行,那么您可能需要针对 VC++ 进行编程。另一个“好处”是您用 VC++ 编写的代码是您可以编写的 C++/C++11 的最小子集,因此最终它应该可以编译到任何地方。当然,这与使用漂亮的 C++11 并享受它的想法背道而驰,所以……明智地选择你的毒药。
回答by Puppy
VC's C++11 support is far from complete, but it does include the most important user-facing features.
VC 的 C++11 支持还远未完成,但它确实包含了最重要的面向用户的功能。
And here's the other thing. In my experience, it is fine to install MinGW or Clang on Windows, but you're going to have some inconvenience because hardly anybody precompiles binaries for those compilers for Windows (whereas lots of people precompile binaries for Visual Studio).
这是另一件事。根据我的经验,在 Windows 上安装 MinGW 或 Clang 没问题,但是您会遇到一些不便,因为几乎没有人为 Windows 的这些编译器预编译二进制文件(而很多人为 Visual Studio 预编译二进制文件)。
In addition, there are as far as I am aware no environments for Windows which are remotely as advanced as Visual Studio for things like graphical debugging, intellisense, and stuff like that. When I tried Code::Blocks it just didn't work, realistically.
此外,据我所知,在 Windows 环境中,没有像 Visual Studio 那样先进的 Windows 环境,可以进行图形调试、智能感知等类似的事情。当我尝试 Code::Blocks 时,它实际上不起作用。
回答by bames53
You can see herefor a comprehensive comparison of compiler support for C++11 language features. Here'ssome info on VS's C++11/14 roadmap.
您可以在此处查看对 C++11 语言功能的编译器支持的全面比较。这是VS 的 C++11/14 路线图的一些信息。
MSVC is lagging behind the other major C++ compilers but it's still got support for many of the most important features.
MSVC 落后于其他主要的 C++ 编译器,但它仍然支持许多最重要的功能。
auto, lambdas, and rvalue references are available from VS10. IIRC there's a caveat with rvalue references that the compiler doesn't generate move construction and move assignment operators.
variadic templates and initializer lists are available in the VS2013 preview, including library support.
type aliasing (i.e., typedefs with the
using
keyword) is expected to be available in VS 2013 RTM.
VS10 提供了 auto、lambdas 和 rvalue 引用。IIRC 有一个带有右值引用的警告,即编译器不会生成移动构造和移动赋值运算符。
VS2013 预览版中提供了可变参数模板和初始值设定项列表,包括库支持。
类型别名(即带有
using
关键字的typedefs )预计将在 VS 2013 RTM 中可用。
If you don't need to interoperate with binaries generated by VS then installing another compiler such as GCC is workable. I understand Clang can also work in a mingw environment, with libstdc++ rather than libc++.
如果您不需要与 VS 生成的二进制文件进行互操作,那么安装另一个编译器(例如 GCC)是可行的。我知道 Clang 也可以在 mingw 环境中工作,使用 libstdc++ 而不是 libc++。
回答by Jake
The nuwen distro is AWESOME! It is MinGW but it comes out much quicker than MinGW as new GCC releases come out. It also comes with all of boost and other useful libraries already compiled. It is all I use on windows anymore.
nuwen 发行版很棒!它是 MinGW,但随着新 GCC 版本的发布,它的发布速度比 MinGW 快得多。它还附带了所有已经编译的 boost 和其他有用的库。这就是我在 Windows 上使用的全部内容。
回答by piotr
We are using C++11 for a few months already in production software across windows and linux in some here.com products without any problems. We use auto, lambdas, range for... Using Visual studio 2012 and gcc 4.7.
我们已经在 Windows 和 linux 的一些 here.com 产品的生产软件中使用 C++11 几个月了,没有任何问题。我们使用 auto、lambdas、range for... 使用 Visual Studio 2012 和 gcc 4.7。
回答by doctorlove
I have been using VS2012 and used C++11 features where possible. There are some bugs in the implementations and I have found it helpful to have another compiler to hand when I get errors from Visual Studio to compare against.
我一直在使用 VS2012 并尽可能使用 C++11 功能。实现中存在一些错误,我发现当我从 Visual Studio 收到错误进行比较时,使用另一个编译器会很有帮助。
回答by Darren Evans
Clang and GCC to lead the way in terms of C++11 feature support and it appears to be a neck-and-neck race in terms of C++11 support between the two. MSVC is sadly panting trying to keep up and lagging behind. The Nuwen MingGW distro is, as Jake mentions, excellent and appears to be working well with Eclipse (Kepler release) and I didn't encounter too much pain using it with Netbeans 7.4 either. The Nuwen distro is currently at version 11.2 at the time of writing and, as you can see at Stephan's website, is now x64-native, featuring GCC 4.8.1 and Boost 1.54.0, with GCC's default mode also set to C++11.
Clang 和 GCC 在 C++11 功能支持方面处于领先地位,并且在两者之间的 C++11 支持方面似乎是一场势均力敌的竞赛。可悲的是,MSVC 气喘吁吁地试图跟上并落后。正如 Jake 所提到的,Nuwen MingGW 发行版非常出色,并且在 Eclipse(Kepler 版本)上运行良好,而且我在 Netbeans 7.4 中使用它时也没有遇到太多痛苦。在撰写本文时,Nuwen 发行版目前为 11.2 版,正如您在Stephan 的网站上看到的,现在是 x64 原生的,具有 GCC 4.8.1 和 Boost 1.54.0,GCC 的默认模式也设置为 C++ 11.
I'm certainly beginning to use Eclipse Kepler and Nuwen MinGW in preference to MSVC 2012 more and more, but I'm largely a hobbyist C++ programmer still getting my feet wet and may not have hit the more obscure problems that those to whom C++ is their bread and butter may know about.
我当然开始越来越多地使用 Eclipse Kepler 和 Nuwen MinGW,而不是 MSVC 2012,但我在很大程度上是一个业余 C++ 程序员,仍然让我的脚湿透了,可能没有遇到比 C++ 更难解决的问题他们的面包和黄油可能知道。