msys2 installs 3 different shells on the system: msys, mingw32, mingw64; which one should i use? this is a classic question, whose best answer i have seen so far is a post on sourceforge; however, it is a very long answer; here i want to give some brief explanation, saving readers some time;

## what is msys2

msys2 stands for minimal system 2, which is a mininal environment for building native windows software; msys2 is based on:

• cygwin: a posix compatibility layer on windows;

• mingw-w64: a cross compiler and related tools, targeting windows build;

msys2 is designed to create an environment for users to comfortably run cross compilers such as mingw-w64; msys2 also provides useful tools, such as bash shell, autotools, package manager, etc., to facilitate software building; many of these tools come from the unix world and require posix compatibility; msys2 provides posix compatibility with its msys-2.0.dll, which is derived from cygwin1.dll in the cygwin project; informally, you can think of msys2 as a “small cygwin” that provides mingw-w64 and other related tools for building native windows software;

## compiler toolchains

msys2 provides 3 compiler toolchains:

• /usr/bin/gcc:

this toolchain produces binary linked to msys2 posix compatibility layer; running ldd on the binary says it is linked with msys-2.0.dll; you can run the compiled binary in msys2, but not in windows cmd;

• /mingw32/bin/gcc;

this toolchain produces native windows 32-bit binary; running ldd on the binary says it is linked with msvcrt.dll, not msys-2.0.dll; you can run the compiled binary in msys2, and in windows cmd;

• /mingw64/bin/gcc;

this toolchain produces native windows 64-bit binary; running ldd on the binary says it is linked with msvcrt.dll, not msys-2.0.dll; you can run the compiled binary in msys2, and in windows cmd;

in short, the mingw toolchains build more “native” binaries, in that they dont depend on the msys2 posix compatibility library msys-2.0.dll; these “native” binaries are the “end” products that msys2 was designed for; binaries compiled with the posix toolchain are often tools used internally in the msys2 environment;

## shells

as we said, msys2 provides 3 shells; they set different environment variables to pick different toolchains and are configured for specific purposes:

• msys:

gcc points to /usr/bin/gcc;

use this shell for most maintenance jobs in msys2: running pacman, etc.;

• mingw32:

gcc points to /mingw32/bin/gcc;

use this shell for cross compiling native 32-bit windows software;

• mingw64:

gcc points to /mingw64/bin/gcc;

use this shell for cross compiling native 64-bit windows software;

in short, most of the time, you want to be in the msys shell; open a mingw shell when you want to cross compile native windows software;

## packages

you may also wonder why some packages, such as curl, exist in both msys and mingw repos;

first, as you can guess, the msys one was compiled using the posix toolchain, while the mingw one was compiled using the mingw toolchain; the former is a posix build, the latter is a win32 build; there is no guarantee that these two variants will always give the same result; even if they do, their performance may vary; because the mingw build is more native, it usually runs faster than the msys build; this difference is more noticeable between msys git and mingw git;

second, if you list their file contents, you will often find the msys package contains only executables, but the mingw package also contains dev files (headers and libs) in addition to executables; if you are simply using curl as a tool, both should work; however, if you are developing your own software that depends on libcurl, then you have to download the mingw package;

as a rule of thumb, when the same software exists in multiple repos, the msys repo is your default choice; use the mingw repo if the msys variant gives a performance problem, or you need dev files as build dependencies;