具有完整 C++11 支持的 Windows C++ 编译器(应该与 Qt 一起使用)

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

Windows C++ compiler with full C++11 support (should work with Qt)

c++windowsqtc++11

提问by SigTerm

Which C++ compiler currently has completeC++11 support on windows platform?

目前哪个 C++ 编译器在 Windows 平台上具有完整的C++11 支持?

Microsoft compiler currently does not have full C++11 support (and it won't be added any time soon).
MinGW g++ (from mingw.org) does not support std::threadout of the box. It also can't compile Qt 4 sources (runs out of memory while building QtGuid4.dll, known workarounds didn't work for me).
I've wasted several days trying to make clang work on windows, managed to compile it, but couldn't enable c++11 support because it required libstdc++ which (I think) wasn't ported to windows platform at that moment. It also isn't supported by Qt 4.

Microsoft 编译器目前没有完整的 C++11 支持(并且不会很快添加)。
MinGW g++(来自 mingw.org)不支持std::thread开箱即用。它也无法编译 Qt 4 源(在构建 QtGuid4.dll 时内存不足,已知的解决方法对我不起作用)。
我已经浪费了几天时间试图在 Windows 上使用 clang,设法编译它,但无法启用 c++11 支持,因为它需要 libstdc++,(我认为)当时没有移植到 windows 平台。Qt 4也不支持它。

What else is there? I've been working for C++03 for a long time, and I'd like to give new features a whirl, but I don't really want a tool that with incomplete support (that'll add extra headache while writing a code) or can run out of memory (on 8GB system) while linking a library.

那里还有什么?我已经为 C++03 工作了很长时间,我想尝试一下新功能,但我真的不想要一个支持不完整的工具(这会在编写代码时增加额外的麻烦)代码)或在链接库时内存不足(在 8GB 系统上)。

I'm working on windows 7 64bit, and although having 64bit support would be nice, I'm mostly interested in 32bit applications, so ability to produce 64bit executables is optional.

我正在使用 Windows 7 64 位,虽然有 64 位支持会很好,但我最感兴趣的是 32 位应用程序,因此生成 64 位可执行文件的能力是可选的。

Any suggestions?

有什么建议?

回答by Alexander Shukaev

First of all, see Status of Experimental C++11 Support in GCC 4.8. Only one proposal is not officially implemented yet. Then, have a look at Implementation Status of C++11 in libstdc++. As you can see some features are yet to be implemented. Nevertheless, we can state that C++11 support in GCC is more or less completeand usable.

首先,请参阅GCC 4.8 中实验性 C++11 支持的状态。只有一项提案尚未正式实施。然后,看看C++11 在libstdc++. 如您所见,有些功能尚未实现。尽管如此,我们可以说 GCC 中的 C++11 支持或多或少是完整和可用的。

Now, concerning Windows: probablydefinitely the best native(not Cygwin!) port of GCC, which I personally consider production-quality, is MinGW-w64. You can download it here. The current (at the time of writing) latest version is based on GCC 4.8.2. It already has support for std::thread. What's more, it offers all the possible variations:

现在,关于 Windows:可能绝对是GCC最好的本地(不是Cygwin!)端口,我个人认为它是生产质量的,是MinGW-w64。你可以在这里下载。当前(在撰写本文时)最新版本基于 GCC 4.8.2。它已经支持. 更重要的是,它提供了所有可能的变化:std::thread

  • 64-bit targets;
  • 32-bit targets;
  • Win32 threads;
  • POSIX threads;
  • SEH exceptions;
  • DWARF exceptions;
  • SJLJ exceptions.
  • 64 位目标;
  • 32 位目标;
  • Win32 线程;
  • POSIX 线程;
  • SEH 例外;
  • 矮人例外;
  • SJLJ 例外。

NOTE:
Be careful when choosing which distribution to download: for std::threadto be available, you need the one with POSIX threads.

注意:
选择要下载的发行版时要小心:为了std::thread可用,您需要具有 POSIX 线程的发行版。

Furthermore, I confirm that I've built Qt 4.8.4 and 4.8.5 myself numerous times and even targeting 64-bit with this toolchain. But that's not all, here is a list of some highlights that I've personally built with MinGW-w64 so far:

此外,我确认我自己已经多次构建 Qt 4.8.4 和 4.8.5,甚至使用此工具链针对 64 位。但这还不是全部,这里列出了迄今为止我个人使用 MinGW-w64 构建的一些亮点:

I think being able to build such huge and diverse code bases as 64-bit targets with good old GCC for Windows is a miraculous achievement of MinGW-w64 developer team. It once again proves the quality of the toolchain.

我认为能够使用适用于 Windows 的老式 GCC 构建 64 位目标这样庞大而多样的代码库是 MinGW-w64 开发团队的奇迹般的成就。它再次证明了工具链的质量。

Qt 5

Qt 5



I've recently built Qt 5.1.1 using MinGW-w64 4.8.2 targeting x64. All in all, it went pretty smooth, but there are a few minor issues which have to be patched before the build. I've gently collected all the required patches and automated the whole process of patching, building, and installing with a simple batch script. If you are interested, check out my Qt for Windows. The usage is so simple that I'll skip commenting on it and simply let you guys read the batch script. Keep in mind that you need Unix's patch.exeto apply the patches which you could get, for example, from MSYS or MSYS2 (see below). You can obtain Qt 5.1.1 source code here.

我最近使用针对 x64 的 MinGW-w64 4.8.2 构建了 Qt 5.1.1。总而言之,它进行得很顺利,但是在构建之前必须修补一些小问题。我轻轻地收集了所有需要的补丁,并使用一个简单的批处理脚本自动完成了打补丁、构建和安装的整个过程。如果您有兴趣,请查看我的Qt for Windows。用法非常简单,我将跳过对其进行评论,而只是让你们阅读批处理脚本。请记住,您需要 Unixpatch.exe来应用您可以从 MSYS 或 MSYS2 获得的补丁(见下文)。您可以在此处获取 Qt 5.1.1 源代码。

NOTE:
Does not seem reasonable to reinvent the wheel (maintaining personal build scripts and patches for Qt) anymore. MSYS2 (see below) now takes care of everything. That is if you need to rebuild Qt with different options and/or flags, then simply edit the corresponding PKGBUILDfile locally and use the makepkg-mingwutility accordingly.

注意:
重新发明轮子(维护 Qt 的个人构建脚本和补丁)似乎不再合理。MSYS2(见下文)现在处理一切。也就是说,如果您需要使用不同的选项和/或标志重新构建 Qt,那么只需在PKGBUILD本地编辑相应的文件并相应地使用该makepkg-mingw实用程序。

NOTE:
Actually, the Qt project officially recommends using MinGW-w64 and MSYS2.

注意:
实际上,Qt 项目官方推荐使用 MinGW-w64 和 MSYS2

About MSYS2

关于 MSYS2



This was not asked directly, but I feel like adding it here as this is a sister project of MinGW-w64, and it's very useful for anyone who has to develop nativesoftware for Windows using Unix-like environment.

这不是直接问的,但我想在这里添加它,因为这是 MinGW-w64 的姊妹项目,对于必须使用类 Unix 环境为 Windows开发本机软件的任何人都非常有用。

Those of you who have ever used the original MSYSprobably know how old it is. It hasn't been improved for ages, and all the Unix utilities there are already terribly outdated.

那些曾经使用过原始MSYS 的人可能知道它有多老。它已经很久没有改进了,所有的 Unix 实用程序都已经过时了。

Guys who provide builds of MinGW-w64 (listed above), now also provide builds of MSYS2which you can download here. Recently, it came out of beta, so be sure to checkout the latest release. It's built for both x86 and x64 architectures (with the MinGW-w64 toolchain itself). All the utilities are updated to their latest versions. For instance, you can already enjoy things like: Bash 4.2, Make 3.99, Git 1.8.4, and many more; which run natively on Windows out of the box!

提供 MinGW-w64 构建(上面列出)的人现在还提供MSYS2构建,您可以在此处下载。最近,它出来了测试版,所以一定要查看最新版本。它是为 x86 和 x64 架构构建的(使用 MinGW-w64 工具链本身)。所有实用程序都更新为最新版本。例如,您已经可以享受以下内容:Bash 4.2、Make 3.99、Git 1.8.4 等等;它开箱即用地在 Windows 上运行!

NOTE:
Make sure to check their Wikito have a smooth start.

注意:
确保检查他们的Wiki以顺利开始。

A Short Story beyond MinGW-w64

超越 MinGW-w64 的短篇小说



The original MinGWwas very slow on improvements, and its developers didn't even consider adding 64-bit target generation support. One ambitious guy, Kai Tietz, took over it and forked it as his company needed to build 64-bit targets on Windows. That's how MinGW-w64 project was born. Although the primary goal was to add 64-bit support, the developers have improved the toolchain in many aspects and addressed a great deal of other issues. Since then the MinGW-w64 project has grown and now is far ahead of MinGW in terms of quality. When MinGW-w64 proposed to MinGW to join the housesand work together, the developers of MinGW showed inadequate reaction and refused to cooperate. As a result, today there are 2 projects with similar name what sometimes causes confusion, but the differences in quality and support speak for themselves.

最初的MinGW改进非常缓慢,其开发人员甚至没有考虑添加 64 位目标生成支持。由于他的公司需要在 Windows 上构建 64 位目标,一位雄心勃勃的人 Kai Tietz 接管了它并将其分叉。MinGW-w64 项目就是这样诞生的。尽管主要目标是添加 64 位支持,但开发人员已在许多方面改进了工具链并解决了许多其他问题。从那时起,MinGW-w64 项目不断发展,现在在质量方面远远领先于 MinGW。当 MinGW-w64 向 MinGW 提议加入房屋时和合作,MinGW的开发者反应不足,拒绝合作。结果,今天有两个名称相似的项目,有时会引起混淆,但质量和支持的差异不言而喻。

回答by JC_Yang

Core language wise, Clang 3.3 and GCC 4.8.1 is fully C++11 conformance already(whether they're bug-free is yet another topic). Library(STL) wise, Clang 3.3(with libc++, but you know, libc++ is not yet usable in both windows and linux) is the only platform fully conform to C++11.

核心语言方面,Clang 3.3 和 GCC 4.8.1 已经完全符合 C++11(它们是否没有错误是另一个话题)。库(STL)方面,Clang 3.3(带有 libc++,但你知道,libc++ 还不能在 windows 和 linux 中使用)是唯一完全符合 C++11 的平台。

MSVC, the latest, Visual C++2013(currently RC, will be RTM in 2 days and general available in Nov 13) provide much better support for C++11 in both core language and STL, thought not complete yet. STL wise, afaik, it's complete.

MSVC 是最新的 Visual C++2013(目前为 RC,将在 2 天内成为 RTM,11 月 13 日正式发布)在核心语言和 STL 方面对 C++11 提供了更好的支持,但尚未完成。STL 明智的,afaik,它是完整的。

I think that depends on what feature your codes really use. Have all C++11 new features been utilized? If Visual C++2013's feature set can satisfy you, try it. Otherwise, clang has already provide a windows port that can integrate to Visual Studio, and can link to native(msvc c++ runtime) library already(claimed), I think you can also give it a trial.

我认为这取决于您的代码真正使用的功能。是否使用了所有 C++11 新功能?如果 Visual C++2013 的功能集可以满足您,请尝试一下。否则,clang 已经提供了一个可以集成到 Visual Studio 的 windows 端口,并且已经可以链接到本机(msvc c++ 运行时)库(声称),我想你也可以试一试。

Addition: Visual C++11/14 conformance roadmap https://udta1g.blu.livefilestore.com/y2pMXBJL7l2a5UOf_pXnLXghSUhPWK8w5skFyc50SVFcMjVwa1guQnM6R0NNLN1buBUNPGbLBejpYXXBXSbqshQKKWVfQxvJjk2jGRPPbL-UBu7gaao4RxifZgPXY5ksdei/image1.png?psid=1

补充:Visual C++11/14 一致性路线图 https://udta1g.blu.livefilestore.com/y2pMXBJL7l2a5UOf_pXnLXghSUhPWK8w5skFyc50SVFcMjVwa1guQnM6R0NNLN1buBUNPGbLBejpYXXQBXKpZfgRbjpYXXQBXPZfgRbjpYXXQBX7vLBejpYXXQBXPZFgRbjpxypxpx7vlbjpxypxnlxghsuhPWK8w5skFyc50SVFcMjVwa1

回答by Richard Matheson

Clang has complete support of windows (modulo Windows standard library bugs in libc++) You can download an "official" windows build of clang 3.3 from here: http://www.llvm.org/builds/

Clang 完全支持 windows(libc++ 中的模 Windows 标准库错误)您可以从这里下载 clang 3.3 的“官方”windows 版本:http: //www.llvm.org/builds/

It doesn't include libc++ so you'll need to download either that or your standard library of choice. I'd recommend using libc++ if possible, as this is currently the most complete library implementation, although I don't know how well it works on windows.

它不包含 libc++,因此您需要下载该库或您选择的标准库。如果可能,我建议使用 libc++,因为这是目前最完整的库实现,尽管我不知道它在 Windows 上的效果如何。