Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC on Cygwin coexisting with MinGW

Tags:

cygwin

mingw

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?

like image 605
aplm Avatar asked Jun 15 '10 02:06

aplm


2 Answers

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.

like image 184
Joshua Avatar answered Oct 14 '22 20:10

Joshua


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.

like image 44
Warren Young Avatar answered Oct 14 '22 18:10

Warren Young