43

Since "gcc -mno-cygwin" does not work anymore, I was looking for a way to get a MinGW-targeted GCC running within my Cygwin environment. (Running a MSYS environment is not an option at this point.)

The Cygwin installer offers a package "gcc-mingw", which installs, among others:

lib/gcc/i686-pc-mingw32/3.4.4/cc1.exe
lib/gcc/i686-pc-mingw32/3.4.4/collect2.exe
lib/gcc/i686-pc-mingw32/3.4.4/crtbegin.o
lib/gcc/i686-pc-mingw32/3.4.4/crtend.o

What is absent is the "gcc" frontend. So, how do I actually invoke this compiler? I hopefully don't have to go through "cc1" manually, have I?

I googled, but couldn't find anything relevant on the subject...

DevSolar
  • 67,862
  • 21
  • 134
  • 209

4 Answers4

35

As you already found, you can use gcc-3 with -mno-cygwin. The other possibility is to install the 32-bit and/or 64-bit toolchains from the MinGW-w64 project, which have been packaged for Cygwin very recently and hence are available through setup.exe now. Don't be put off by the rather confusing executable names: i686-w64-mingw32-gcc is the 32-bit compiler and x86_64-w64-mingw32-gcc is the 64-bit one.

ak2
  • 6,629
  • 31
  • 27
  • 2
    This actually works. Any idea why they keep an apparently non-functional package "gcc-mingw" in there and hide the working stuff as "i686-w64-mingw32-gcc"? – DevSolar Sep 24 '10 at 11:41
  • I think the gcc-mingw packages are part of the `gcc-3 -mno-cygwin` functionality. They don't actually contain anything except postinstall scripts that create links which I guess are needed for that. Those funny names follow the usual target triplet pattern for cross-compilers: cpu-vendor-os, with vendor==w64 (for MinGW-w64) and os==mingw32 (for hystorical reasons). – ak2 Sep 24 '10 at 19:16
  • 3
    Note that as of June '12 at least, the string to run the MinGW compiler from Cygwin after installing the toolchain is simply `mingw-gcc`. This resolves the issue raised by the [comments](http://stackoverflow.com/questions/3776098/cygwin-how-to-actually-use-gcc-mingw#comment3998032_3776118) in the [post below](http://stackoverflow.com/a/3776118/564181). – Chris Krycho Jun 28 '12 at 19:41
  • 1
    Just be careful which mingw-toolchain you use. The "true" mingw32 is win32-based ("mingw-gcc" probably being from that and not from the cygwin gang) and use Windows paths e.g. They are thus somewhat incompatible with the cygwin native versions (producing .d files with different path notations etc.). The cygwin-based gcc4 cross-compiler is one of the two mentioned in the answer. – thoni56 Aug 29 '12 at 17:36
3

Further searches revealed that the MinGW-targeted cross-compiler is not ready yet, and that one has to either use GCC v3 with -mno-cygwin, or install a cross-compiler manually (see link above)...

DevSolar
  • 67,862
  • 21
  • 134
  • 209
2

After installing the MingW g++ package for Cygwin (mingw64-x86_64-gcc-g++), I also struggled to figure out how to invoke it.

Thanks to this wiki, I found out the command was x86_64-w64-mingw32-g++. Then I did alias g++='x86_64-w64-mingw32-g++' and g++ started working as expected.

serg06
  • 2,027
  • 1
  • 18
  • 26
1

Cygwin homepage says that "Individual packages like bash, gcc, less, etc. are released independently of the DLL.".

Here you can find how to install gcc under cygwin, so you should also select gcc package during install not only gcc-mingw.

rics
  • 5,494
  • 5
  • 33
  • 42
  • I have installed (among others) gcc, gcc4, and gcc-mingw. My question is how to actually *reach* the MinGW-targeting GCC. "gcc" obviously doesn't do it, "gcc -mno-cygwin" neither, and there is no such thing as a "gcc-mingw". – DevSolar Sep 23 '10 at 07:18
  • I see it is not so simple as I first thought. Here (http://cygwin.com/ml/cygwin/2009-10/msg00061.html) I found a possible solution. – rics Sep 23 '10 at 07:34
  • I also found this do-it-yourself solution: http://sourceforge.net/apps/trac/mingw-w64/wiki/Cross%20Win32%20and%20Win64%20compiler – rics Sep 23 '10 at 07:39