10

Basically I want to compile C/C++ using the GCC on Windows. The two competing platforms, as i see it, are MinGW and Cygwin. Each have their own benifits and limitations. MinGW compiles for Windows, whereas Cygwin needs the cygwin .dll. However installing libraries on MinGW is difficult, whereas on cygwin it's easier, using the setup.exe as a 'package manager'.

My question is what's the best way to compile on Windows. Would it be better to use MinGW and struggle with libraries (in which case is there an easy way of installing libraries on MinGW). Or should I use Cygwin, if so how do I get it to compile without needing the cygwin .dll, effectively compile for normal Windows.

2
  • Subjective question. I prefer mingw, because you're not coding against a compatibility layer. Assuming you want a free (as in beer) environment, there's still some options you miss -- the Express editions of Visual Studio, or the command line only version of VC++. Commented Oct 28, 2009 at 19:29
  • Old post, but in case people stumble upon it, I want to link to this post telling about setting up a C environment on Windows: thecodetailor.net/c-environment-on-windows. Since it describes setting it up through MSYS2, that eases package/library management. Commented Mar 18, 2020 at 16:23

9 Answers 9

7

The easiest and best way to compile on windows is to use visual studio express. It is free. A good reason for using cygwin is for cross platform builds. A good reason to use gcc is it supports some compiler candy the Microsoft compiler doesn't.

But all in all VC++ Express is the way to go for windows only development.

Sign up to request clarification or add additional context in comments.

2 Comments

If you are using Visual Studio Express, you can't legally make commercial applications without violating the terms of service.
@Andres: # Can I use Express Editions for commercial use? Yes, there are no licensing restrictions for applications built using Visual Studio Express Editions.
5

There is always the option of using -mno-cygwin with Cygwin to compile against Windows libraries like MinGW does:

gcc -mno-cygwin file.c -o test

It's not an easy choice and mainly depends on how much you will rely on other libraries. Cygwin really adds an additional layer, which is heavier but "emulates" the Linux environment better than MinGW.

Edit:

Qt Creator allows you to compile with MinGW on Windows (and gcc on Linux, ...), has an IDE that makes debugging more friendly than gdb. If you need libraries, you still have the option of using the Qt libraries. That would be a good alternate solution to the Visual Studio if you really want to stick to gcc for future portability.

4 Comments

The -mno-cygwin flag doesn't create a static binary, it creates one that isn't linked to the cygwin.dll -- in essence, a "bare" win32 program. In practice (modulo stuff like different code generation from different compiler versions) it's exactly what you get from the mingw compiler.
Right, thanks for pointing that out Andy, I'll edit the answer.
@Andy: I don't really know, but wouldn't Cygwin libc (and possibly some other stock libs) depend on cygwin.dll? I.e. if you do -mno-cygwin, wouldn't you be limited to Win32 API only?
@Pavel: From the Cygwin FAQ (cygwin.com/faq.html), 6.10: The -mno-cygwin flag to gcc makes gcc link against standard Microsoft DLLs instead of Cygwin. This is desirable for native Windows programs that don't need a UNIX emulation layer. This is not to be confused with 'MinGW' (Minimalist GNU for Windows), which is a completely separate effort.. But if the program uses the Cygwin API, then it is not possible to stay independent of cygwin1.dll and there is no static linking.
3

You might want to look at CodeBlocks. It is generally used to build WxWidgets apps, but it wraps MinGW nicely.

1 Comment

I use it to play with gcc 4.4's C++0x support. Crashes sometimes but functional in normal case.
1

Actually, there's option #3: if your edition of Windows permits it, you can install Microsoft Services For Unix / Subsystem for Unix Applications, and then get gcc from SUACommunity. It has a package manager, too. Of those 3 options, this will give you behavior closest to a true Unix system.

However, the resulting applications aren't Win32 applications; they're SUA applications, and will require SUA to run. If you write code for yourself, it's usually not a problem if you write code for yourself, but if you want to write and distribute a proper Windows application, I would suggest staying away from anything that tries to emulate Unix, so MinGW it is.

Comments

1

Qt Creator comes with MinGW as standard and can be used to build projects that don't actually use the Qt framework.

2 Comments

I'd say go with Mingw, if only because of Qt Creator. It's really good.
I had already mentioned that in my post (except the link) ;-) But yes, that would be my first choice to develop with gcc. Hopefully with an update to 4.6 soon.
0

There's an easy to install MinGW wrapped GCC at equation.com. Click "Programming Tools" then "Fortran, C, C++", download the release you prefer, install and use.

Comments

0

One possible method is to use CMake which can build Visual Studio project from your sources and then compile from Visual Studio. It can build project for other IDEs too, so you can go cross platform.

Comments

0

I think the answer depends on whether you intend to use libraries or compile programs that are targeted to POSIX or a POSIX-based target. That's what Cygwin is intended for, while MinGW is more intended for compiling Windows-targeted programs using GCC.

Comments

0

Another option is TDM MinGW: http://www.tdragon.net/recentgcc/

It's basically an unofficial fork of MinGW with the latest GCC compiler available for both 32- and 64bit windows machines. Even some MinGW developers themselves use it.

Equation Gcc is even better: http://www.equation.com/servlet/equation.cmd?fa=fortran

1 Comment

It's not a fork; they just release much much more often than the official mingw.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.