官方wiki文檔中有簡介msys2,比較CygWIN 的異同,以及與 MinGW 關系。
下面截取其中片段並翻譯,以快速了解 MSYS。
MSYS2 is software distribution and a building platform for Windows. It provides a Unix-like environment, a command-line interface and a software repository making it easier to install, use, build and port software on Windows. That means Bash, Autotools, Make, Git, GCC, GDB..., all easily installable through Pacman, a fully-featured package manager.
MSYS2 是針對 Windows 的軟件分發和構建平台。 它提供了一個類 uni x的環境,一個命令行界面和一個軟件庫,使得在Windows上安裝、使用、構建和移植軟件更加容易。 這意味着 Bash, Autotools, Make, Git, GCC, GDB… ,都可以通過Pacman,一個全功能的包管理器輕松安裝。
It is an independent rewrite of MSys, based on modern Cygwin (POSIX compatibility layer) and MinGW-w64 with the aim of better interoperability with native Windows software.
它是基於現代Cygwin (POSIX兼容層)和 MinGW-w64,對MSys的獨立重寫版本,目標是與本地Windows軟件更好的互操作性。
1. 子系統 Subsystems
MSYS2 consists of three subsystems and their corresponding package repositories, msys2, mingw32, and mingw64.
MSYS2由三個子系統及其相應的軟件包庫MSYS2、mingw32和mingw64組成。
- mingw 子系統提供原生的 Windows 程序,構建是為了與其他 Windows 程序合作,而獨立於其他子系統。
- msys2 子系統為編譯軟件、包管理和 shell腳本 提供了一個主要與 posix 兼容的仿真環境。
2. 文件系統 File system
Paths | Contents |
---|---|
/bin, /dev, /home, /opt, /proc, /tmp, /var | essential POSIX stuff |
/etc, /usr | msys2 subsystem |
/mingw32, /mingw64 | mingw subsystems |
/c, /d, ... | mount points for Windows drives |
/.xml, /maintenancetool., InstallationLog.txt | (un)installer |
/autorebase.bat, /msys2_shell.cmd, /msys2.ico | shell entry points |
3. 安裝和升級
參考 https://www.msys2.org/wiki/MSYS2-installation/
4. Cygwin vs MSYS2 [1]
-
目標:Cygwin 試圖將 posix 兼容的環境引入 Windows,使大多 linux 軟件可在 Cygwin 上構建和運行。Cygwin 的主要構成是完成這一目標的。 MSYS2 試圖提供一個構建本地 Windows 軟件的環境。主要構成是提供windows 構建和運行的軟件包和庫,只是大部分軟件使用的是與unix緊密耦合的GNU構建工具,因此也是 posix 兼容的。
-
包管理:MSYS2 使用 Pacman 管理,Cygwin只附帶Cygwin相關的軟件。它使用自己的包管理系統,通常稱為setup.exe。
- msys2: Containing MSYS2-dependent software
- mingw64: Containing 64-bit native Windows software (compiled with mingw-w64 x86_64 toolchain)
- mingw32: Containing 32-bit native Windows software (compiled with mingw-w64 i686 toolchain)
-
運行時:Cygwin提供了一個名為cygwin1.dll的運行時庫,它在必要時提供了POSIX兼容層。這個庫的MSYS2變體稱為msys-2.0.dll。
5.MSYS2 vs MinGW[2]
網上關於MSYS和MinGW介紹也比較多,區別和聯系也不少。打個形象但不恰當的比方:
MSYS 相當於操作系統(如Windows),這個操作系統提供的軟件、接口等和Linux相似
MinGW 相當於開發工具包(如MSVC),這個開發工具包可以運行在 MSYS 下,包里的工具也可以運行在Windows下,編譯結果是Windows程序。
主要常見問題:
-
MSYS 也可以安裝 gcc,make等工具(我們稱之為MSYS編譯器),這些工具安裝在 /usr/bin 路徑下,MinGW 的工具安裝在 /mingw/bin 下。這兩套工具都可以編譯程序。所以初次使用時經常會出現這樣的疑問:究竟運行 msys2.exe 還是 mingw64.exe 來啟動控制台?
回答: MSYS2 和 MinGW 都提供 gcc,但是屬於兩個完全不同的工具鏈。前者屬於 msys2-devel ,后者屬於 mingw-w64-$arch-toolchain。使用 mingw-gcc 編譯的目標文件是原生的,而使用 msys2-gcc 編譯的目標文件依賴於 msys-2.0.dll 提供的虛擬 POSIX 環境。如果你要編譯的東西強依賴於 POSIX syscall (比如 fork 等),那么就要用 MSYS2 的 gcc。而如果是要當做一個 release 拿去給別人用的,用 MinGW 的 gcc 好些。當然,事情也不絕對,對於前者你也可以給源文件 patch 一個 MinGW 移植,對於后者也可以用 MSYS2 然后附帶上 msys-2.0.dll。根據我自己的經驗,如果你使用目標文件的環境就是 MSYS2 的話,用 MSYS2 工具鏈編譯的程序要比 MinGW 工具鏈的穩定一些(對 ruby, python 等工具而言)。
-
MSYS的CMake 和 MinGW 的 CMake ?
- MSYS中安裝的CMake默認配置 Makefile 項目,會生成一個 Makefile 文件。
- MinGW中安裝的CMake默認配置 MSVC 項目,會生成一個 VS 的 sln 文件(沒錯,生成 VS 工程)。如果要用 MinGW ,需要 cmake -G "MinGW Makefiles" 以生成供 mingw32-make 編譯的 makefile 文件。
-
如何在 Windows 上直接調用 MinGW ?
回答:在環境變量 PATH 中加入 /mingw64/bin 就可以直接使用 gcc 等工具了。但是,如果使用的是絕對路徑(如 D:\msys2\mingw64\bin\gcc.exe )則編譯沒有結果,應該是失敗了。這樣其實在 Windows 上可以不用單獨安裝 CMake ,直接在 MinGW64 中安裝一個就可以了。
6. MinGW 安裝[3]

- Architecture:i686是32位,x86_64是64位系統。
- Thread: win32對應開發Windows程序,posix對應其它
- Exception: 當Architecture是i686時,此處可選sjlj和dwarf,當Architecture是x86_64時,此處可選sjlj和seh