MSYS2 has something called "environments": CLANG64, UCRT64, MINGW64, MSYS and others.
MSYS2 has multiple versions of each compiler and library, one per environment. The compilers in each environment have slighly different settings. Some compilers/tools are missing from some environments.
This tutorial uses CLANG64 by default (but can be adapted to other ones too). UCRT64 is the officially recommended default. MINGW64 is also popular.
-
Each environment has its own packages (compilers, libraries, tools, etc). The packages for each environment can be distinguished by the common prefix in their names, e.g.
mingw-w64-clang-x86_64-...for CLANG64. -
Each environment installs its packages to a separate directory under
C:\msys64. E.g. CLANG64 installs toC:\msys64\clang64. -
Each environment has its own shortcut in the Start menu, which opens a terminal with the respective directory added to PATH:
The current environment is displayed in the terminal in magenta text:
E.g.
MSYS2 CLANG64shortcut starts a terminal withC:\msys64\clang64\binin the PATH.All MSYS2 terminals ignore the system-wide PATH setting by default, and set a fully custom PATH for themselves.
-
Use the correct shortcut. (see above)
-
Install the packages with the right prefix. E.g. in CLANG64 install packages named
mingw-w64-clang-x86_64-....Run
echo $MINGW_PACKAGE_PREFIXin MSYS2 terminal to know the right prefix for your environment.⚠ Don't install unprefixed packages for compilers and libraries. Only use them for simple command-line tools (
grep,sed, etc), only if there's no prefixed alternative. (See below for more details.) There are exceptions from this rule, e.g. bothmakeandmingw-w64-...-makeare viable. -
If you want to add MSYS2 to PATH, add the correct directory:
C:\msys64\clang64\binfor CLANG64 and so on.
One of the environments is called MSYS, and it's special.
Don't confuse it with the whole MSYS2, and don't confuse it with the ancient MSYS1 (which sometimes was called just "MSYS").
-
It hosts the system packages that don't belong to other environments (such as
pacman). -
Package names for
MSYSare not prefixed with anything. (pacman -S clanginstalls MSYS Clang). They are installed toC:\msys64\usr, and some directly toC:\msys64. -
Packages in MSYS are based on Cygwin (or rather on MSYS2's own fork of it).
MSYS compilers create Cygwin applications, which isn't something you normally want for your applications. Don't install MSYS compilers and libraries unless you know what you're doing. They are also often outdated.
-
All other environments "inherit" from
MSYS, in the sense that they add it to the PATH (they addC:\msys64\usr\binafterC:\msys64\<environment>\bin). -
⚠ MSYS environment always being in PATH can cause confusion.
E.g. if you install
pacman -S gccAND don't installmingw-w64-...-gccfor your environment, and then try to rungccfrom your environment's MSYS terminal, you'll end up running MSYS GCC (C:\msys64\usr\bin\gcc.exe), which won't be compatible with any libraries you install in your environment, and so on.
MINGW64, UCRT64, and CLANG64 are the three popular environments.
CLANG64 is limited to the Clang compiler and the tools associated with it (libc++ only, no libstdc++; LLD linker only, no LD; llvm-ar only, no Binutils ar, etc). While UCRT64 and MINGW64 have both Clang and GCC, and both sets of tools.
On the other side, CLANG64 supports sanitizers, unlike other environments. And (in rare cases), Clang-based tools seem to work a bit better in it (e.g. at the time of writing, LLDB spams harmless warnings to the console on UCRT64).
UCRT64 is the closest equivalent for CLANG64 that's not limited to Clang/LLVM tools.
In UCRT64 and MINGW64, GCC is considered to be the primary compiler, most packages there are compiled with it (by MSYS2 developers).
In UCRT64 and MINGW64, Clang uses libstdc++ (GCC's C++ standard library) by default (instead of Clang's own libc++, which has to be installed separately with pacman -S ...-libc++ and enabled by passing -stdlib=libc++ compiler flag).
In UCRT64 and MINGW64, both GCC and Clang use the LD linker by default, but Clang's LLD linker can be installed separately (pacman -S ...-lld) and enabled (in either compiler) using -fuse-ld=lld flag (when linking). Since LLD is way faster, it might be a good idea to always use it. Unlike LLD, LD is sensitive to the order of the -l flags.
MINGW64 uses the old implementation of the C standard library (Microsoft's msvcrt.dll), while UCRT64 and CLANG64 use the new one (ucrtbase.dll, also by Microsoft).
ucrtbase.dll adds support for UTF-8 in paths (which has to be manually enabled), and otherwise there's not much difference.
Consult Choosing the compiler for more information.
-
For most
...64environments, there are...32counterparts that compile 32-bit applications as opposed to 64-bit. (CLANG32vsCLANG64, etc.)Those are being gradually phased out, and there's little reason to use them.
-
This can be used to compile ARM applications for Windows ARM laptops. Though they can run normal (x86/x86_64) applications as well via emulation.

