7

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?

Community
  • 1
  • 1
simon
  • 1,125
  • 1
  • 10
  • 18

1 Answers1

4

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).

Christoph
  • 149,808
  • 36
  • 172
  • 230
  • So I assume this win32 pthreads port is included in MinGW? – simon Mar 07 '12 at 11:13
  • @simon: it didn't use to be, but apparently it's a MinGW base package since 2010-02-18 (see http://sourceforge.net/projects/mingw/files/MinGW/Base/pthreads-w32/) – Christoph Mar 07 '12 at 11:33
  • @Christoph Cygwin doesn't enforce a fixed DLL memory layout as such, but it does need to be able to load DLLs in a forked process at the same addresses as the parent. – ak2 Mar 07 '12 at 12:09
  • @ak2: see http://code.google.com/p/chromium/wiki/CygwinDllRemappingFailure - the load address hints of cygwin DLLs need to be compatible, *effectively* enforcing a fixed memory layout; you need to call `rebaseall` when it changes... – Christoph Mar 07 '12 at 16:25