GCC on Cygwin coexisting with MinGW

前端 未结 5 1094
Happy的楠姐
Happy的楠姐 2021-02-04 18:58

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 c

5条回答
  •  难免孤独
    2021-02-04 19:46

    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.

提交回复
热议问题