Install MSYS2 on Windows
MinGW brings GNU compiler tools to Windows since the late 1990s.
MSYS2 provides numerous developer tools including MinGW on Windows using pacman
package manager.
Install MSYS2 by downloading msys2-x86_64-*.exe and run the installer, installing to $HOME/msys64. MSYS2 needs to be on a non-FAT / non-ExFAT drive capable of symbolic links such as NTFS.
Start the MSYS2 console in the Windows Start menu. Update MSYS2 to get the latest packages in the MSYS2 terminal. Run this command multiple times until it says “nothing to do”.
pacman -Syuu
To use GCC and other MSYS2 / MinGW64 programs from PowerShell without disrupting other compiler use, create file “gcc.ps1” containing:
$r="$HOME/msys64/ucrt64"
$b="$r/bin"
$Env:CC="$b/gcc"
$Env:FC="$b/gfortran"
$Env:CXX="$b/g++"
# important to put UCRT first to avoid "collect2.exe: error: ld returned 116 exit status" and DLL Hell
$Env:Path = "$b;$Env:Path"
$Env:CMAKE_PREFIX_PATH="$r"
When it’s desired to use MSYS from a PowerShell prompt run “gcc.ps1”.
From MSYS2 command prompt, search for packages like:
pacman -Ss gcc
MSYS2 packages of interest for scientific computing include: gcc, gdb, gcc-fortran, clang, boost, lapack, scalapack, HDF5, ninja, make, pkgconf, aspell.
You may need to reorder directories in the Windows Path variable. For example GNU Octave may need to be moved lower in the Path list or removed from Path.
If you find that MSYS2 is using more 500 MB, try clearing the package cache of old package versions
pacman -Sc
The MSYS2 latest package update feed shows recently updated packages. The MSYS2 Install reference is also useful. PowerShell per-session variable set is useful to set CC, FC, CXX to single intended compiler to build systems.
Alternatives
As compared to Cygwin, MSYS2 works from the Windows Command Prompt or PowerShell. MSYS2 provides native Window binaries. Cygwin does not have a command-line package installer.
Windows Subsystem for Linux is strongly supported, but does not give Windows binaries unless cross-compiling.