tags:

views:

142

answers:

3

It is possible to have two versions of GCC to coexist: the native windows MinGW version and the cygwin linux version? Things get problematic when on Cygwin the system tries to compile with the MinGW version of GCC, and vice versa. How can I keep both versions of GCC?

+1  A: 

I have both of them installed and coexisting peacefully. Cygwin is installed in c:\cygwin while MinGW is installed in c:\msys\mingw. I didn't have to do anything unusual to make them coexist since their environments are set by their respective startup shortcuts.

There must be some specific step in your installation that caused them to become coupled in some way. If you describe your installation sequence and locations perhaps someone can offer additional advice.

Amardeep
A: 

Psychic debugging suggests you have one or both in your global path. Take both out of your global path (gcc should yield "bad command or file name" or similar run directly from cmd.exe) and set up the shortcuts so they load the proper environment for each.

Joshua
A: 

The way I keep them separate is to use the Cygwin environment by default, exclusively. The MinGW stuff isn't in my default PATH, and I don't use any MSYS programs. For day to day use you can't tell I have MinGW installed at all.

In those rare instances when I need to test something with MinGW, I run this shell script from the Cygwin Bash prompt, which I call mingw:

#!/bin/sh
PATH=/cygpath/c/mingw/bin:/cygpath/c/windows/system32:/cygpath/c/cygwin/bin
echo "Say 'exit' to leave MinGW shell and restore Cygwin environment."
/usr/bin/bash --rcfile ~/.mingwrc

Adjust the PATH to taste. The only important thing about it is that it puts the MinGW bin directory ahead of the Cygwin bin directory. You probably still want the Cygwin bin directory in the PATH for vi, ls, etc.

The last line of that script runs this script, ~/.mingwrc:

alias make=mingw32-make
PS1='MinGW: \W \$ '

You can't combine these two scripts due to the way Bash works. The second script contains things that can only happen once the "MinGW shell" is running. The PS1 assignment reminds you that you're in a MinGW shell, and the alias ensures that typing "make" runs MinGW's own make(1) program instead of Cygwin's, since my MinGW Makefiles use DOS commands, not Bourne shell commands, and this is one of the differences in the MinGW port of GNU make. You'd leave that alias line out if you want to use the MinGW compiler with Cygwin make.

When you "exit" out of the MinGW sub-shell, you restore your previous PS1, PATH and aliases.

Warren Young