views:

579

answers:

9

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.

+3  A: 

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.

Byron Whitlock
If you are using Visual Studio Express, you can't legally make commercial applications without violating the terms of service.
Andres
@Andres: this is simply false. See http://www.microsoft.com/express/support/faq/
Pavel Minaev
@Andres: # Can I use Express Editions for commercial use?Yes, there are no licensing restrictions for applications built using Visual Studio Express Editions.
fuzzy lollipop
+4  A: 

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.

RedGlyph
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.
Andy Ross
Right, thanks for pointing that out Andy, I'll edit the answer.
RedGlyph
@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 Minaev
@Pavel: From the Cygwin FAQ (http://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.
RedGlyph
A: 

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.

pmg
+2  A: 

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

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

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

http://qt.nokia.com/products/developer-tools

Rob
I'd say go with Mingw, if only because of Qt Creator. It's really good.
Pavel Minaev
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.
RedGlyph
A: 

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.

oold
+1  A: 

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.

Pavel Minaev
A: 

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.

Michael Burr
A: 

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

It's basically an unofficial fork of MinGW with the latest GCC compiler. Even some MinGW developers themselves use it.

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