Cygwin 上的 GCC 与 MinGW 共存
两个版本的 GCC 可以共存:本机 Windows MinGW 版本和 cygwin linux 版本吗?当在 Cygwin 上系统尝试使用 MinGW 版本的 GCC 进行编译时,就会出现问题,反之亦然。如何保留两个版本的 GCC?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
心理调试建议您的全局路径中有一个或两个。将两者从全局路径中取出(gcc 应该产生“错误的命令或文件名”或直接从 cmd.exe 运行类似的命令)并设置快捷方式,以便它们为每个路径加载正确的环境。
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.
我将它们分开的方法是默认情况下专门使用 Cygwin 环境。 MinGW 的东西不在我的默认路径中,而且我不使用任何 MSYS 程序。对于日常使用,你根本看不出我已经安装了 MinGW。
在极少数情况下,当我需要使用 MinGW 测试某些内容时,我会从 Cygwin Bash 提示符运行此 shell 脚本,我将其称为
mingw
:根据需要调整 PATH。唯一重要的是它将 MinGW bin 目录放在 Cygwin bin 目录之前。您可能仍然需要 vi、ls 等的 PATH 中的 Cygwin bin 目录。
该脚本的最后一行运行此脚本,
~/.mingwrc
:您无法组合这两个脚本,因为Bash 的工作方式。第二个脚本包含只有在“MinGW shell”运行时才会发生的事情。 PS1 分配提醒您,您处于 MinGW shell 中,并且别名确保键入“make”运行 MinGW 自己的 make(1) 程序而不是 Cygwin 的程序,因为我的 MinGW Makefile 使用 DOS 命令,而不是 Bourne shell 命令,并且此是 GNU make 的 MinGW 移植的差异之一。如果您想将 MinGW 编译器与 Cygwin make 一起使用,则可以保留该别名行。
当您“退出”MinGW 子 shell 时,您将恢复之前的 PS1、PATH 和别名。
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
: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
: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.
我已经安装了它们并和平共处。 Cygwin 安装在 c:\cygwin 中,而 MinGW 安装在 c:\msys\mingw 中。我不必做任何不寻常的事情来使它们共存,因为它们的环境是由各自的启动快捷方式设置的。
您的安装中必须有某些特定步骤导致它们以某种方式耦合。如果您描述您的安装顺序和位置,也许有人可以提供其他建议。
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.
将两者都从全局路径中删除。然后新建一个
*.cmd
文件,内容如下(以Cygwin为例):您可以在命令窗口中输入
path
进行检查。现在您可以使用 cygwin 了。该环境仅在
cmd.exe
内有效。Take both out of global path. Then create a new
*.cmd
file with the following (takes Cygwin as example):You can type
path
in the command window to check.Now you can work with cygwin. The environment only be valid within the
cmd.exe
.安装它们不会造成任何损害,就像磁盘上有两组文件一样。显然,它甚至不会轻易发生冲突。
在路径变量中选择默认值,即哪一个位于另一个的顶部(请注意,这对 shell 执行有效)。
或者,可以在各自的 IDE 中指定默认值。
对我来说,我之前安装了 mingw,并配置了代码块。但是后来当我安装 Cygwin 时,我修改了路径并使其优先级更高,mingw 可以完美地与代码块配合使用。
Having both of them installed causes no harm, its just like having 2 set of files on the disk. Apparently it doesn't even clash easily.
The default one is selected in the path variable, i.e, which one is the top of the other (Note that is valid for shell executions).
Alternatively, defaults can be specified in respective IDEs.
For me ,I earlier had mingw installed for which codeblocks was configured.But later when I installed Cygwin I modified the path and made it higher priority mingw was perfectly working with codeblocks.