views:

5044

answers:

10

I want to make my C++ project cross platform, and I'm considering using Cygwin/MinGW. But what is the difference between them ?

Another question is whether I will be able to run the binary on a system without Cygwin/MinGW ?

+1  A: 

Cygwin emulates entire POSIX environment, while MinGW is minimal tool set for compilation only (compiles native Win application.) So if you want to make your project cross-platform the choice between the two is obvious, MinGW.

Although you might consider using VS on Windows, GCC on Linux/Unices. Most open source projects do that (e.g. Firefox or Python).

vartec
+10  A: 

Cygwin uses a DLL, cygwin.dll, (or maybe a set of DLLs) to provide a POSIX-like runtime on Windows.

MinGW compiles to a native Win32 application.

If you build something with Cygwin, any system you install it to will also need the Cygwin DLL(s). A MinGW application does not need any special runtime.

Michael Burr
+14  A: 

Wikipedia does a comparison here.

From Cygwin's website:

  • Cygwin is a Linux-like environment for Windows. It consists of two parts: A DLL (cygwin1.dll) which acts as a Linux API emulation layer providing substantial Linux API functionality.
  • A collection of tools which provide Linux look and feel.

From Mingw's website:

MinGW ("Minimalistic GNU for Windows") is a collection of freely available and freely distributable Windows specific header files and import libraries combined with GNU toolsets that allow one to produce native Windows programs that do not rely on any 3rd-party C runtime DLLs

dirkgently
+33  A: 

cygwin is an attempt to create a complete UNIX/POSIX environment on Windows. To do this it uses various DLLs that unfortunately have a user-unfriendly license. MinGW is a C/C++ compiler suite which allows you to create Windows executables without dependancy on such DLLs - you only need the normal MSVC runtimes.

You can also get a small UNIX/POSIX like environment, compiled with MinGW called MSYS. It doesn't have anywhere near all the features of Cygwin, but is ideal for programmers wanting to use MinGW.

anon
Sorry Neil, but to say that the license is user-unfriendly is wrong and misleading, whatever your feelings on copyleft are. Cygwin is dual licensed Free software; either the GPL or a commercial license for proprietary use. That's about as user friendly as you can get and still hope to make any money on the venture. http://cygwin.com/faq/faq-nochunks.html#faq.what.free - it is not "friendly" to folk that want to distribute non-GPL'd proprietary software without a commercial license, but that is not a *user* issue.
rq
But if I want to release free non-GPL software? Sorry, I'm not a GPL fan, is all.
anon
@Neil: It cuts both ways. If you want to redistribute Microsoft's MSVC runtimes, you must comply with their redistributables license. But what if I want to release software that doesn't comply? Sorry, I'm not a Microsoft fan, is all ;)
Dan Moulding
@Dan You don't need to redistribute the runtime that MinGW uses - it's part of Windows.
anon
+2  A: 

Cygwin is is a Unix-like environment and command-line interface for Microsoft Windows.

Mingw is a native software port of the GNU Compiler Collection (GCC) to Microsoft Windows, along with a set of freely distributable import libraries and header files for the Windows API. MinGW allows developers to create native Microsoft Windows applications.

You can run binaries generated with mingw without the cygwin environment, provided that all necessary libraries (DLLs) are present.

gimel
+5  A: 

Note that utility behaviour can genuinely vary between the two.

For example, Cygwin tar can fork - because fork() is supported in the DLL - where the mingw version cannot. This is a problem when trying to compile mysql from source.

Blank Xavier
+6  A: 

Don't overlook AT&T's U/Win software, which is designed to help you compile Unix applications on windows. Like Cygwin they have to run against a library; in their case POSIX.DLL. The AT&T guys are terrific engineers (same group that brought you ksh and dot) and their stuff is worth checking out.

Norman Ramsey
+10  A: 

Fairly simple:

  • Compile something in Cygwin and you are compiling it for Cygwin.
  • Compile something in MingW and you are compiling it for Windows.

Cygwin is good when your app absolutely needs a POSIX environment to run - it is sometimes easier to port something to Cygwin than it is to port it to Windows, because Cygwin is a layer on top of Windows that emulates a POSIX environment. If you compile something for Cygwin then it will need to be run within the Cygwin environment, as provided by cygwin1.dll. For portability, you could distribute this dll with your project, if you were willing to comply with the relevant license.

MingW is a Windows port of the GNU compiler tools, like GCC, Make, Bash, etc, which run directly in Windows without any emulation layer. By default it will compile to a native Win32 target, complete with .exe and .dll files, though you could also cross-compile with the right settings. It is an alternative to Microsoft Visual C compiler and its associated linking/make tools in a way.

thomasrutter
+17  A: 

To add to the other answers, Cygwin comes with the MingW libaries and headers and you can compile without linking to the cygwin1.dll by using -mno-cygwin flag with gcc. I greatly prefer this to using plain MingW and MSYS.

TrayMan
+1. I did not know that.
j_random_hacker
This does not work any more with cygwin 1.7.6. gcc: The -mno-cygwin flag has been removed; use a mingw-targeted cross-compiler.
sigjuice
A: 

Looks like MSYS is an old cygwin fork. I prefer mingw binaries since they seem to be easier to use (with no installation), but if you want a full environment, not sure what the advantage of MSYS opposed to cygwin bash would be.

eckes