C++ - 在 Windows 上使用 GCC 而不是 MSVC 值得吗?

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

C++ - Is it worth using GCC over MSVC on Windows?

c++visual-c++gcc

提问by Nighteen

I have read some questions about GCC vs MSVC and the development of these compilers such as GCC worth using on Windows to replace MSVC?, Visual Studio or GCC?and GCC vs MS C++ compiler for maintaining API backwards binary compatibility. But those are very outdated questions(2011). With new c++14 features coming things are starting to balance between the two compilers. Is it still worth using Code::Blocks on Windows with all the advantages of using Microsoft Visual Studio such as:

我已经阅读了一些关于 GCC 与 MSVC 以及这些编译器的开发的问题,例如值得在 Windows 上使用以替换 MSVC 的 GCC?Visual Studio 还是 GCC?GCC vs MS C++ 编译器,用于维护 API 向后二进制兼容性。但这些都是非常过时的问题(2011)。随着新的 c++14 特性的出现,两个编译器之间开始平衡。在 Windows 上使用 Code::Blocks 是否仍然值得使用 Microsoft Visual Studio 的所有优点,例如:

  • Native Windows libraries with support to using MFC, ATL, DirectX and other useful Microsoft libraries.
  • Great debugging features, especially when using the disassembly view(it has so many useful features).
  • 本机 Windows 库,支持使用 MFC、ATL、DirectX 和其他有用的 Microsoft 库。
  • 很棒的调试功能,尤其是在使用反汇编视图时(它有很多有用的功能)。

In most of the topics I have read, they always say GCC code generation was better than MSVC's, but the differences in that matter were starting to narrow. Is code generation still better in GCC? What about newest c++ features, which of them is ahead?

在我读过的大多数主题中,他们总是说 GCC 代码生成比 MSVC 更好,但在这方面的差异开始缩小。GCC 中的代码生成仍然更好吗?最新的 C++ 特性怎么样,哪些是领先的?

The biggest advantage I see in using GCC versus MSVC is that:

我认为使用 GCC 与 MSVC 的最大优势在于:

  • It is open source, which makes custom compiler code possible.
  • Easier to make portable code.
  • IT IS FREE.
  • ???Better code generation???
  • 它是开源的,这使得自定义编译器代码成为可能。
  • 更容易制作可移植的代码。
  • 这是免费的。
  • ???更好的代码生成???

C++14 features on GCC: https://gcc.gnu.org/projects/cxx1y.html

GCC 上的 C++14 特性:https: //gcc.gnu.org/projects/cxx1y.html

C++11 and C++14 features on MSVC RTM: http://blogs.msdn.com/b/vcblog/archive/2015/06/19/c-11-14-17-features-in-vs-2015-rtm.aspx

MSVC RTM 上的 C++11 和 C++14 特性:http: //blogs.msdn.com/b/vcblog/archive/2015/06/19/c-11-14-17-features-in-vs- 2015-rtm.aspx

回答by o11c

Yes.

是的。

Although MSVC has made someprogress toward newer C++ standards, it is still woefullybehind, even on C++98 status (which is conveniently excluded from that status page).

尽管 MSVC 在更新的 C++ 标准方面取得了一些进展,但它仍然远远落后,即使在 C++98 状态(它被方便地从该状态页面中排除)。

From what I've read recently, the MSVC team does not even have a concrete plan for fixing some of the old issues, e.g. with name lookup and template instantiation.

从我最近阅读的内容来看,MSVC 团队甚至没有解决一些旧问题的具体计划,例如名称查找和模板实例化。

Now, when you can use MSVC with clang as the compiler, that might be reason to stop using GCC. However, for my purposes, I find that clang has much inferior diagnostics (and sometimes inferior code) so I still use GCC as my primary compiler and just use clang as a backup.

现在,当您可以使用带有 clang 的 MSVC 作为编译器时,这可能是停止使用 GCC 的原因。然而,就我的目的而言,我发现 clang 的诊断很差(有时代码也很差),所以我仍然使用 GCC 作为我的主要编译器,只使用 clang 作为备份。

And as @Cheersandhth says, it's good to use two compilers. Though maybe look at Intel's compiler.

正如@Cheersandhth 所说,最好使用两个编译器。虽然也许看看英特尔的编译器。

回答by Cheers and hth. - Alf

The elaborated question is an open invitation to opinions; there's even some provocation about "best IDE" etc. Even so the question as posed in the title,

详细阐述的问题是对意见的公开邀请;甚至还有一些关于“最佳 IDE”等的挑衅。即便如此,标题中提出的问题,

C++ - Is GCC [i.e. g++] worth using on Windows nowadays?

C++ - GCC [ie g++] 现在是否值得在 Windows 上使用?

has a simple fact-based answer, namely yes, because

有一个简单的基于事实的答案,即yes,因为

  • it's a good idea to expose code to at least two compilers, when that's possible, e.g. the combo Visual C++ and g++, and

  • g++ is good for purposes of learning.

  • 在可能的情况下,将代码公开给至少两个编译器是个好主意,例如组合 Visual C++ 和 g++,以及

  • g++ 有利于学习。

The main problem with g++ in Windows is that its API binding only covers the Windows XP API fully, and nothingvery little after.

Windows 中 g++ 的主要问题是它的 API 绑定只完全覆盖了 Windows XP API,并且 没有之后很少。