76

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?
Xeo
  • 129,499
  • 52
  • 291
  • 397
Nairou
  • 3,585
  • 5
  • 29
  • 47
  • You may find that waiting for Visual Studio 11 may be [an option](http://stackoverflow.com/questions/7421825/c11-features-in-visual-studio-11) to consider as well. – vcsjones Nov 06 '11 at 18:05
  • 1
    If you want to use mingw you should consider different ide too – David Heffernan Nov 06 '11 at 18:08
  • @vcsjones: The site I linked to was regarding the C++11 changes in Visual Studio 11. I was not impressed, hence this post. – Nairou Nov 06 '11 at 18:11
  • 1
    @vcsjones FWIW, there have been indications that Microsoft will be releasing compiler updates out-of-band with the normal VS release schedule. Of course, this is Microsoft, so only time will tell. – Michael Price Nov 07 '11 at 19:20
  • 2
    GCC's generated code quality is basically many times better than the MSVC's one. The latter just doesn't know about many optimizations :) – Michael Pankov Feb 02 '12 at 16:05
  • @Constantius got any references to show that? It would certainly add incentive for me to drop MSVC. – Nairou Feb 03 '12 at 20:23
  • @Nairou http://www.linux-kongress.org/2009/slides/compiler_survey_felix_von_leitner.pdf if you'll through the slides, you'll notice many cases of MSVC not-being-smart-enough :) – Michael Pankov Feb 03 '12 at 23:52
  • 3
    While late to this party, I bypassed VS2012 and went straight to VS2013 and it is amazing compared to VS2010. I have only had one issue initializing atomic_bool with bool and there are a couple of bizarre windowing issues you can generally work around. If you care about writing correct C++ then you will want this. – graham.reeds Dec 19 '13 at 09:09

8 Answers8

68

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.

Damon
  • 67,688
  • 20
  • 135
  • 185
  • 3
    That is kind of the impression I've been getting... Resulting application will be great, but the development process will be greatly diminished compared to what MSVC offers. Makes me wonder how Linux developers manage! – Nairou Nov 07 '11 at 15:13
  • 15
    I haven't checked in a while, so I might be wrong, but last time I checked code::blocks didn't really convince me. Personally I would recommend either Eclipse CDT or if that uses too much resources QTCreator for mingw development – Grizzly Nov 13 '11 at 22:38
  • 5
    Eclipse has admittedly _much_ better code completion, but it also weights about 20 times as much and takes 10 times as long to start up, etc. It's probably more powerful in its 2 million build options too, though personally this rather confuses me than being helpful. I guess it is a matter of personal taste (plus, I'm probably a bit unfairly biased to Code::Blocks). But sure enough, Eclipse may be a viable alternative. – Damon Nov 14 '11 at 10:46
  • 4
    That's funny; in the few projects I've tried, Mingw compiles significantly more quickly and the resulting code runs faster - despite the code being being profiled and optimized using MSC (i.e. tuned for MSC not gcc). – Eamon Nerbonne Feb 15 '12 at 11:59
  • @EamonNerbonne: Unless one cheats (e.g. use precompiled headers with MinGW and none with MSVC), MinGW/gcc compiles significantly (up to 2x) slower than almost any competitor, especially with optimizations. Luckily, unless dependencies are terrible, this is not really much of an issue. The reason is both the actual compiler speed, and the fact that the toolchain does a lot of forks (sometimes 4-5 per source), which is fine under Unix-like systems but pretty devastating under Windows. Plus, GNU `ld` performance is just abysmal. About application performance, I wholeheartedly agree... – Damon Feb 15 '12 at 12:32
  • ... MinGW consistenly produces better code that runs faster than any competitors I know, including MSVC (that's speaking of real code, not cheating on benchmarks). – Damon Feb 15 '12 at 12:34
  • @Damon: I'm using precompiled headers on MSCV, and *not* on Mingw; because they're easier to set up for msc and because; well, the slowdown in MSC is just rather annoying so I've spent more effort getting it to compile fast. I *am* using a lot of heavy template code from boost and some from eigen, so perhaps MSC doesn't efficiently deal with that; but any way I try and slice it; the compiles with MSC just take longer (I don't think they take quite 2x as long, but it's around that). – Eamon Nerbonne Feb 17 '12 at 09:37
  • I use Eclipse CDT with MinGW on Windows, and I have found its code navigation/completion features to be on par with, if not better than, MSVC's. – HighCommander4 Mar 30 '12 at 21:43
  • Okay guys, sorry to barge into this prolonged discussion. Found these new things by experience: (1) NetBeans is much more light-weight than Eclipse CDT for C++ compilation with MinGW / MinGW w64. (2) MinGW w64 (and the debugger) now work very well for most things, so that beats MVC C++ Express (which only compiles for x86). (3) MinGW code is leaner and meaner, therefore faster, even when trying to cut off extra lard in MVC. (4) The new OpenCL plugin for NetBeans C/C++ works great, whereas it's still a pain to get OpenCL support set up in MVC. - Hope this helps all of you C coders out there. – Greg Kramida Apr 25 '12 at 22:13
  • P.S.: (5) recently tried to p/Invoke C/C++ functions from an unmanaged DLL generated with MinGW w64 from a managed C# DLL (MVC#) with great success and pleasure. – Greg Kramida Apr 25 '12 at 22:29
  • 1
    @GregKramida: Regarding point (4) -- Using the WDK can help you link dynamically to the CRT included in the OS (i.e. no need to distribute it with your programs), cutting down on the fat. – user541686 Jan 08 '13 at 17:44
  • Some compile time speed comparisons here http://slashdot.org/topic/cloud/speed-test-2-comparing-c-compilers-on-windows/ – demented hedgehog Jan 29 '14 at 00:55
  • 10
    @Nairou: Being a Linux developer, and speaking only for myself: I don't use an IDE. The command-line tools are powerful, and in contrast to languages like C# or Java, C++ wasn't built for usage with an IDE. – mic_e Oct 24 '14 at 20:35
  • 3
    @Nairou *Makes me wonder how Linux developers manage!* — Linux developers usually using some kind of Vim/Emacs. Great thing when you got comfortable with it. Someone also mentioned already as IDE QtCreator. Recently I used VS2010 through VirtualBox, and I wonder how it is crippled. Though for movement I found VsVim plugin, but its debugger still much worse than the gdb. I.e. I can not set in Visual Studio a breakpoint to set a *temporary* break somewhere in code, and continue. Also I didn't managed to find a command for break to print a memory area… Many things, all didn't fit to a comment. – Hi-Angel Mar 27 '15 at 07:01
  • 7
    **UPDATE:** I believe [CLion](https://www.jetbrains.com/clion/) with its modern design, wealth of features, and CMake integration makes it worthy of being "the best non MSVC IDE on Windows." It's also more actively maintained. – CinchBlue Nov 05 '17 at 22:54
17

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.

danijar
  • 32,406
  • 45
  • 166
  • 297
  • 2
    There is still not a good IDE with the same stability and support like MSVS also CLion plays not in the same ballpark (it's full of bugs and debugging with GDB is a nightmare). – devarni Jul 05 '15 at 14:47
11

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.
rubenvb
  • 74,642
  • 33
  • 187
  • 332
3

I my humble opinion, it's depends how someone started to code in the first place. I've been using g++ and gcc for more than 20 years now but the reason why i keep using gcc is mainly for licensing reasons. Although i like it too when i don't have a bunch of runtime dependencies or dll's to bundle with my stuff since i came from the DOS era, i still like my stuff small and fast. gcc for windows comes with standard win32 libraries and common control but i had to develop my own win32 controls for stuff that might require mcf shit to work properly or just to look nicer.

Although gcc might have strong support over internet, when it comes to win32 stuff, many rely on mcf and vc proprietary stuff so again, one may have to work his own issues around and be creative when difficulty arises.

I think it's all about needs and circumstances. If you are just a hobbyist coders and have the time for researches, creating you own libs and stuff but you want a solid compiler that's around since the late 80's and free, gcc sound perfect for the job.

But in the industry visual studio is a must if you want to be competitive and stay in the race. Many hardware manufacturers would prefer bundling visual studio compatible libraries for they hardware over some opensource gnu stuff.

That's my two cents.

2

To be honest, C++ should be handled with MS Visual Studio. If you want to make cross-platform or Unix apps, use GCC. GCC works and can be used with any IDE other than Visual Studio. Even Visual Studio Code can use GCC. Code::Blocks, Eclipse IDE for C/C++ developers, CLion, Notepad++ and even the good ol' tool we've always known, Notepad works with GCC. And finally, on a PC with low disk space, installing Visual Studio's "Desktop Development with C++" is something like 5 GB, if it was to be useful. And this is where GCC hits MSVC hard. It has native C support. MSVC can compile C, but only with a lot of fine-tuning. It takes a lot of time and effort to finally be able to compile. The final verdict:

If MSVC works, it hella works! If MSVC doesn't work, it HELLA DON'T WORK.

If GCC installs, it works, and if it doesn't work, it's the IDE's problem.

GCC is for people who don't mind spending 4 hours at the computer making it work properly. MSVC is for those who don't care about C and want it to install without any pokin' around.

1

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.

IanNorton
  • 7,145
  • 2
  • 25
  • 28
1

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.

timday
  • 24,582
  • 12
  • 83
  • 135
  • 16
    The Intel compiler intentionally disables many of its optimizations when the code executes on AMD chips. – mikerobi Nov 06 '11 at 18:21
  • @mikerobi Wouldn't that be 'antitrust' or something? Remember M$ getting sued for making it easier to use Internet Explorer, and not having APIs/etc allowing other browsers to integrate into the shell, or something like that. – Mateen Ulhaq Nov 06 '11 at 18:27
  • 6
    @muntoo - no it's "a safety feature", since Intel aren't experts on AMD they couldn't be sure that their optimizations were correct ;-) – Martin Beckett Nov 06 '11 at 18:30
  • 1
    @MartinBeckett Ah, that makes sense! And if the government could give them some money, they might be able to hire five more programmers to optimize for their largest competitor's chips... – Mateen Ulhaq Nov 06 '11 at 18:35
  • 6
    @MartinBeckett, Intel developers don't need to be AMD experts to know that AMD's SSE instructions behave identically to there own. 3rd party compiler authors don't have inside expertise on AMD or Intel chips, but they don't have any trouble adding optimization. – mikerobi Nov 06 '11 at 18:41
  • 1
    @muntoo, the number of programmers has nothing to do with it. The same optimization would work on AMD chips. It is just a matter of giving their products a competitive advantage. – mikerobi Nov 06 '11 at 18:44
  • 1
    I remember this being easily circumvented (after-compile binary patch to remove the CPUID check) and I thought even removed in later ICC releases due to false competition. – rubenvb Nov 06 '11 at 19:23
  • 9
    @mikerobi - you mean an almost monopolistic technology company might not have been entirely truthful in it's justification of anti-competitive behavior ? I'm shocked – Martin Beckett Nov 06 '11 at 19:59
  • 2
    See the links from this question for more on the AMD issue... http://stackoverflow.com/questions/839667/how-much-should-i-worry-about-the-intel-c-compiler-emitting-suboptimal-code-fo – timday Nov 07 '11 at 10:25
1

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.

mikerobi
  • 20,527
  • 5
  • 46
  • 42
  • 5
    mikerobi: perhaps you don't see widespread use, but please look a bit further. Pretty much anything hauled over from the Linux world (here I think of things like VLC, FFMPEG, GSL, OpenOffice, KDE...) all use MinGW (GCC). When was the last time you saw a library built for all versions of MSVC? Because each version, including SP releases also breaks ABI, GCC can use one version for any GCC version (from 4.2, which is really old). I think MSVC is in the disadvantage here. – rubenvb Nov 06 '11 at 19:13
  • 1
    @rebenvb, I did not say that it is not widespread, I said that it could be "more widespread." Linux is widespread, but that doesn't mean there isn't a lot of room for growth. I was thinking of the disapointing number of open source applications that are still compiled with Visual C++: Chrome, Firefox, MySQL, PostGreSQL, Blender, Apache to name a few. The fact that official Python releases are compiled with MSVC, is a major headache for me and forces me to use cygwin. I very badly wish you were correct when you said anything from Linux is compiled with gcc. – mikerobi Nov 06 '11 at 19:35
  • Ah, yes, I forgot about the semi-commercial things. It's funny when you think of how hackish the Mozilla build system has to be (heavily modified MSYS) to be able to build with MSVC. – rubenvb Nov 07 '11 at 10:14
  • 1
    GCC DLLs can be used with MSVC EXEs if you know how to. extern "C" is here for THAT reason! Same for GetProcAddress() – Петър Петров Jul 21 '12 at 16:19
  • 1
    @ПетърПетров, that does not work with C++, unless you build a C interface to bridge the gap. That completely changes how you have to design your application. – mikerobi Jul 21 '12 at 18:00
  • DLLs are designed to be used as C interfaces primarily. There are protocols (Ugly hacks :P) that MSVC uses to mask these things away. Every DLL have "C" exports, even it it is advertised as a "C++" DLL. MSVC DLLs just hack that in. In MingW/GCC, you can name your C exports as you like. The way both "gamble" C++ Class methods is different, but there are macros, and you can make a macro that extend to a stub that is properly manually "gambled". – Петър Петров Feb 14 '13 at 06:54