GCC worth using on Windows to replace MSVC?

2020-05-11 05:36发布

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.

I thought maybe the upcoming version of Visual Studio would add these new features. However, after reading this it looks like very little is going to change.

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:

  • 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?

7条回答
我命由我不由天
2楼-- · 2020-05-11 06:16

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.

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.

查看更多
ゆ 、 Hurt°
3楼-- · 2020-05-11 06:17

GCC's C++11 support is quite phenomenal (and quite up to par with standards conformance, now that <regex> has been implemented).

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).

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.

Apart from this, to answer your questions:

  1. 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.
  2. 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.
  3. Code quality is just as good as you'd want it. See above.
  4. 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.
查看更多
冷血范
4楼-- · 2020-05-11 06:28

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 ).

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.

查看更多
家丑人穷心不美
5楼-- · 2020-05-11 06:30

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

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 .

查看更多
爱情/是我丢掉的垃圾
6楼-- · 2020-05-11 06:37

MSVC has the huge advantage of coming with an IDE that has no equals under Windows, including debugger support.

The probably best alternative for MinGW would be Code::Blocks, but there are worlds in between, especially regarding code completion and the debugger.

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).

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.

MinGW also compiles significantly slower than MSVC (though precompiled headers help a little).

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).

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.

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.

查看更多
趁早两清
7楼-- · 2020-05-11 06:38

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.

查看更多
登录 后发表回答