Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to use Cygwin or MinGW to compile C code? [duplicate]

I'm wondering in what situations one uses Cygwin to compile C code and when one would opt for MinGW. I came over What is the difference between Cygwin and MinGW? describing the differences between Cygwin and MinGW.

As far as I understood, one could say the following:

  • Cygwin: Allows compiling C source code for POSIX compliant operating systems to run on Windows (requires the cygwin1.dll). For example, I could compile an application using the pthreads API for Windows, although Windows itself does not implement the API.
  • MinGW: Allows compiling Windows compliant C source code. So using the example from above, I could not use the pthreads API when compiling with gcc in MinGW but would be required to use the threads API offered by Windows. Instead of using the MinGW gcc compiler, I could also be using a different compiler, e.g. the one that comes with VC++.

However, my understanding seems to be wrong, because I was able to compile a dummy program that included pthread.h with MinGW. What did I understand wrongly?

like image 582
simon Avatar asked Mar 07 '12 10:03

simon


People also ask

Should I use Cygwin or MinGW?

It doesn't have anywhere near all the features of Cygwin, but is ideal for programmers wanting to use MinGW. MinGW is higher performance than Cygwin, but it's also 32-bit which may be a problem with your applications. There is a 64-bit environment similar to MinGW but it's a different project.

Can I have both MinGW and Cygwin?

You can install MinGW-W64 under "Cygwin" by selecting these packages (under "Devel" category): mingw64-x86_64-gcc-core : 64-bit C compiler for native 64-bit Windows. The executable is " x86_64-w64-mingw32-gcc ".

Is MinGW necessary C?

In MinGW, you can write native windows programs (by calling the native Win32 C interface), but you cannot compile everything uses POSIX functionality not present in windows. The most evident case is the missing of the standard <thread> interface of MinGW and a limited <locale> support.

Why is Cygwin needed?

Cygwin offers users a Linux-like experience in a Windows environment. This capability helps developers migrate applications from Unix or Linux to Windows-based systems and makes it easier to support their applications running on the Windows platform. At the heart of the Cygwin collection of tools is the cygwin1.


1 Answers

Your understanding is essentially correct. However, there's a win32 pthreads port, which is a thin wrapper over the native threads API.

A more appropriate example would be fork(), which cannot be emulated easily on win32. To do so, Cygwin enforces a fixed DLL memory layout, and things will explode if a library can't be loaded where it's supposed to go (cue rebaseall).

like image 190
Christoph Avatar answered Sep 29 '22 14:09

Christoph