msys2, using standard windows console

2019-08-02 16:03发布

问题:

I use Console2 (link1 link2), it's like a wrapper around the standard console, but allows to copypaste text with ctrl-shift-c and ctrl-shift-v. I find it much more comfortable than the consoles that come with msys2, they have like ctrl-ins shift-ins weirdness. And having two different consoles around isn't good.

How can I use Console2 to launch the compiler? I'd add C:\msys64\mingw32\bin to PATH, but I don't want to have too many exe and dll around in PATH, don't want to distribute something that depends on libgcc_s_dw2-1.dll by accident.

Also, I need to be able to switch between mingw32 and mingw64 compilers somehow.

Tried reading c:/msys64/msys2_shell.cmd, don't understand what's in it.

Switching to windows command line probably requires to move from unix shell commands to windows ones. I could rewrite some makefiles I'm working with, it's not that much of a problem.

Maybe I could go the other way, to use msys2 console in my everyday life. I only use it to launch youtube-dl and one other program I wrote anyway. It would require making copypasting easier, and some way to switch between mingw32 and mingw64.

回答1:

https://stackoverflow.com/posts/46015587/edit

Temporary solution: create three files g3.bat, g6.bat and gg.bat, and put them in one of the PATH directories. They allow to temporarily add or delete mingw32 or mingw64 in PATH.

g3.bat:

call gg.bat
SET PATH=%PATH%C:\msys64\mingw32\bin;

g6.bat:

call gg.bat
SET PATH=%PATH%C:\msys64\mingw64\bin;

gg.bat:

set PATH=%PATH:C:\msys64\mingw32\bin;=%
set PATH=%PATH:C:\msys64\mingw64\bin;=%

Call this to check the result: echo %PATH%


Version 2, that tries to not use leading ;

It almost works, but gg.bat still leaves leading ; behind. I could use set PATH=%PATH:;C:\msys64\mingw32\bin=% instead (notice extra ; to the right of %PATH:), but it would break if C:\msys64\mingw32\bin is at the beginning of PATH.

Also, I'm not sure if "" is necessary there or not.

g3.bat:

call gg.bat
SET PATH=%PATH%;C:\msys64\mingw32\bin

g6.bat:

call gg.bat
SET PATH=%PATH%;C:\msys64\mingw64\bin

gg.bat:

set PATH=%PATH:C:\msys64\mingw32\bin=%
set PATH=%PATH:C:\msys64\mingw64\bin=%
set "PATH=%PATH:;;=;%"

Version 3, "eeh whatever":

gg.bat:

set PATH=%PATH:;C:\msys64\mingw32\bin=%
set PATH=%PATH:;C:\msys64\mingw64\bin=%

set PATH=%PATH:C:\msys64\mingw32\bin;=%
set PATH=%PATH:C:\msys64\mingw64\bin;=%

set PATH=%PATH:C:\msys64\mingw32\bin=%
set PATH=%PATH:C:\msys64\mingw64\bin=%

set PATH=%PATH:;;=;%


标签: cmd msys2