C++ 值得在 Windows 上使用 GCC 来代替 MSVC?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8029092/
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
GCC worth using on Windows to replace MSVC?
提问by Nairou
I currently develop in C++ on Windows, using Visual Studio 2010. After the official announcement of C++11, I have begun to use some of its features that are already available in MSVC. But, as expected, the great majority of the new changes are not supported.
我目前在 Windows 上使用 C++ 进行开发,使用 Visual Studio 2010。在 C++11 正式发布后,我开始使用 MSVC 中已经提供的一些功能。但是,正如预期的那样,大多数新更改不受支持。
I thought maybe the upcoming version of Visual Studio would add these new features. However, after reading thisit looks like very little is going to change.
我想也许即将推出的 Visual Studio 版本会添加这些新功能。然而,读完这篇文章后,看起来几乎没有什么改变。
And so, I'm curious about the feasibility of using GCC on Windows rather than MSVC, as it appears to support the great majority of C++11 already. As far as I can tell, this would mean using MinGW (I haven't seen any other native Windows versions of GCC). But I have questions about whether this would be worth trying:
因此,我很好奇在 Windows 上使用 GCC 而不是 MSVC 的可行性,因为它似乎已经支持绝大多数 C++11。据我所知,这意味着使用 MinGW(我还没有看到任何其他本地 Windows 版本的 GCC)。但我对这是否值得一试有疑问:
- Can it be used as a drop-in replacement for cl.exe, or would it involve a lot of hacks and compatibility issues to get Visual Studio to use a different compiler?
- The main selling point for Visual Studio, in my opinion, is it's debugger. Is that still usable if you use a different compiler?
- Since GCC comes from the *nix world, and isn't native to Windows, are there code quality issues with creating native Windows applications, versus using the native MSVC compiler? (If it matters: most of my projects are games.)
- In other words, will the quality of my compiled exe's suffer from using a non-Windows-native compiler?
- 它可以用作 cl.exe 的直接替代品,还是会涉及很多技巧和兼容性问题以使 Visual Studio 使用不同的编译器?
- 在我看来,Visual Studio 的主要卖点是它的调试器。如果您使用不同的编译器,它仍然可用吗?
- 由于 GCC 来自 *nix 世界,并且不是 Windows 原生的,与使用原生 MSVC 编译器相比,创建原生 Windows 应用程序是否存在代码质量问题?(如果重要的话:我的大部分项目都是游戏。)
- 换句话说,我编译的 exe 的质量会因使用非 Windows 本地编译器而受到影响吗?
采纳答案by Damon
MSVC has the huge advantage of coming with an IDE that has no equals under Windows, including debugger support.
MSVC 有一个巨大的优势,它带有一个在 Windows 下无与伦比的 IDE,包括调试器支持。
The probably best alternative for MinGW would be Code::Blocks, but there are worlds in between, especially regarding code completion and the debugger.
对于 MinGW 来说,可能最好的选择是 Code::Blocks,但两者之间有很多世界,尤其是在代码完成和调试器方面。
Also, MSVC lets you use some proprietary Microsoft stuff (MFC, ATL, and possibly others) that MinGW has no support for, and makes using GDI+ and DirectX easier and more straightforward (though it is possible to do both with MinGW).
此外,MSVC 允许您使用 MinGW 不支持的某些 Microsoft 专有内容(MFC、ATL 和可能的其他内容),并使使用 GDI+ 和 DirectX 变得更容易和更直接(尽管使用 MinGW 可以同时执行这两项操作)。
Cygwin, as mentioned in another post, will have extra dependencies and possible license issues (the dependency is GPL, so your programs must be, too). MinGW does not have any such dependency or issue.
Cygwin,正如在另一篇文章中提到的,将有额外的依赖项和可能的许可证问题(依赖项是 GPL,所以你的程序也必须是)。MinGW 没有任何此类依赖性或问题。
MinGW also compiles significantlyslower than MSVC (though precompiled headers help a little).
MinGW的还会编译显著慢于MSVC(尽管预编译的头有点帮助)。
Despite all that, GCC/MinGW is an entirely reliable quality compiler, which in my opinion outperforms any to date available version of MSVC in terms of quality of generated code.
This is somewhat less pronounced with the most recent versions of MSVC, but still visible. Especially for anything related to SSE, intrinsics, and inline assembly, GCC has been totally anihilating MSVC ever since (though they're slowly catching up).
尽管如此,GCC/MinGW 是一个质量完全可靠的编译器,在我看来,它在生成代码的质量方面优于任何迄今为止可用的 MSVC 版本。
这在最新版本的 MSVC 中不太明显,但仍然可见。特别是对于与 SSE、内在函数和内联汇编相关的任何事情,从那时起,GCC 就一直在彻底摧毁 MSVC(尽管他们正在慢慢赶上)。
Standards compliance is a lot better in GCC too, which can be a double-edged sword (because it can mean that some of your code won't compile on the more conforming compiler!), as is C++11 support.
GCC 中的标准合规性也好得多,这可能是一把双刃剑(因为这可能意味着您的某些代码无法在更符合标准的编译器上编译!),C++11 支持也是如此。
MinGW optionally also supports DW2 exceptions, which are totally incompatible with the "normal" flavour and take more space in the executable, but on the positive side are "practically zero cost" in runtime.
MinGW 还可选地支持 DW2 异常,它与“正常”风格完全不兼容,并在可执行文件中占用更多空间,但从积极的方面来说,运行时“几乎为零成本”。
回答by danijar
I want to add some information because the field may have changed since the question was asked.
我想添加一些信息,因为自提出问题以来该字段可能已更改。
The main problem for switching away from MSVC was the lack of a good IDE that flawlessly integrates with MinGW . Visual Studio is a very powerful tool and was the only player on Windows for quite some time. However, Jetbrains released a preview version of their new C++ IDE CLion some days ago.
离开 MSVC 的主要问题是缺乏与 MinGW 完美集成的良好 IDE。Visual Studio 是一个非常强大的工具,并且在很长一段时间内是 Windows 上唯一的播放器。然而,Jetbrains 几天前发布了他们新的 C++ IDE CLion 的预览版。
The main benefit comes when working on cross platform applications. In this case, a GCC based tool chain can make life much easier. Moreover, CLion narrowly integrates with CMake, which is also a big plus compared to Visual Studio. Therefore, in my opinion, it is worth to consider switching to MinGW now.
主要好处是在跨平台应用程序上工作。在这种情况下,基于 GCC 的工具链可以让生活变得更轻松。此外,CLion 与 CMake 紧密集成,这与 Visual Studio 相比也是一个很大的优势。因此,在我看来,现在考虑切换到 MinGW 是值得的。
回答by rubenvb
GCC's C++11 support is quite phenomenal (and quite up to par with standards conformance, now that <regex>
has been implemented).
GCC 的 C++11 支持非常出色(并且非常符合标准,现在<regex>
已经实现了)。
If you replace your compiler, you'll need to make sure every dependency can be built with that new compiler. They're not made to be substitutable plugins (although Clang is working on becoming that way).
如果您更换编译器,则需要确保可以使用新编译器构建每个依赖项。它们不是可替代的插件(尽管Clang 正在努力变成那样)。
GCC is a fine compiler, and can produce code that has pretty much the same performance, if not better, than MSVC. It is missing some low-level Windows-specific features though.
GCC 是一个很好的编译器,可以生成性能与 MSVC 几乎相同甚至更好的代码。不过,它缺少一些低级别的 Windows 特定功能。
Apart from this, to answer your questions:
除此之外,回答你的问题:
- To get VS to use GCC as a compiler, you'd pretty much need to turn to makefiles or custom build steps all the way. You'd be much better off compiling from the commandline and using CMake or something similar.
- You cannot use the VS debugger for GCC code. GCC outputs GDB compatible debug information, and the VS debug format is proprietary, so nothing will change in that area anytime soon.
- Code quality is just as good as you'd want it. See above.
- No, the quality of your code will actually increase, as GCC will point out several assumed standard extensions MSVC would hide from you. All self-respecting open source projects can be compiled with GCC.
- 要让 VS 使用 GCC 作为编译器,您几乎需要一直使用 makefile 或自定义构建步骤。从命令行编译并使用 CMake 或类似的东西会更好。
- 您不能将 VS 调试器用于 GCC 代码。GCC 输出 GDB 兼容的调试信息,并且 VS 调试格式是专有的,因此该领域不会很快发生任何变化。
- 代码质量与您想要的一样好。看上面。
- 不,您的代码质量实际上会提高,因为 GCC 会指出 MSVC 会隐藏的几个假定标准扩展。所有自尊的开源项目都可以用 GCC 编译。
回答by IanNorton
It can't be used as a direct swap-out replacement for the microsoft compilers, for a start it has a vastly different set of command line arguments and compiler specific options.
它不能用作微软编译器的直接换出替代品,首先它具有一组截然不同的命令行参数和编译器特定选项。
You can make use of MinGW or Cygwin to write software but introduce extra dependencies ( especially in the case of cygwin ).
您可以使用 MinGW 或 Cygwin 来编写软件,但会引入额外的依赖项(尤其是在 cygwin 的情况下)。
One not often touted advantage of gcc over cl is that gcc can be used with ccache to drastically speed up rebuilds or distcc to build using several other machines as compiler slaves.
gcc 相对于 cl 的一个不常被吹捧的优势是 gcc 可以与 ccache 一起使用以显着加速重建或 distcc 使用其他几台机器作为编译器从属机器进行构建。
回答by timday
Consider the Intel compiler (or "Composer" as they seem to have taken to calling it) as another option. I'm not too sure where its C++11 support is at compared with MS (certainly it has lambdas), but it does integrate very nicely with VisualStudio (e.g different projects within a solution can use the Intel or MS compilers) and there's also been some efforts made to match the MS compiler commandline options.
考虑将英特尔编译器(或他们似乎已经习惯调用它的“作曲家”)作为另一种选择。我不太确定它的 C++11 支持与 MS 相比在哪里(当然它有 lambdas),但它确实与 VisualStudio 很好地集成(例如,解决方案中的不同项目可以使用 Intel 或 MS 编译器)并且有还做出了一些努力来匹配 MS 编译器命令行选项。
回答by mikerobi
GCC and MSVC use different name mangling conventions for C++. C++ dlls compiled by one compiler can not be used in applications compiled with the other. I believe this is the main reason we don't see more widespread use of gcc in windows.
GCC 和 MSVC 对 C++ 使用不同的名称修改约定。由一个编译器编译的 C++ dll 不能在用另一个编译器编译的应用程序中使用。我相信这是我们在 Windows 中没有看到更广泛使用 gcc 的主要原因。
回答by TraceKira
Just use visualGDB Visual studio 2017 plugin. It can use any mingw flavour. 64/32 bit ext TDM-GCC-64(posix) ,SysGCC(mingw 64) , MinGw
只需使用 visualGDB Visual Studio 2017 插件。它可以使用任何 mingw 风味。64/32 位扩展 TDM-GCC-64(posix)、SysGCC(mingw 64)、MinGw
Problem sovled .... visual studio 2017 + any kind of mingw version It has Linux , Windows , Android , Raspberry Pi , any Linux , development boards support , Clang intelisense ... Its amazing . 30 Days trial .
问题已解决....visual studio 2017 + 任何类型的 mingw 版本它具有 Linux、Windows、Android、Raspberry Pi、任何 Linux、开发板支持、Clang 智能感知......它令人惊叹。30 天试用。