Install GCC, GFortran, CMake and Make on Windows

Alternative: Install Windows Subsystem for Linux

The GNU compilers, make and Cmake are easily available for native Windows, as follows:

  1. Download MinGW-w64 compiler (gcc, g++ gfortran)
  2. Install to C:\mingw using:

    • Architecture: x86_64
    • Threads: posix
    • Exception: seh

    This also installs GNU make at C:\mingw\bin\mingw32-make.exe.

  3. add c:\mingw\bin to your PATH under Control Panel → System → Advanced.

  4. For convenience, symlink make to mingw32-make:

    cd C:\mingw\bin
    mklink make.exe mingw32-make.exe

    CMake on Windows

    CMake on Windows has a graphical installer cmake*-win64-x64.msi Within the project code directory, in general build programs that have CMakeLists.txt on Windows (and other operating systems) with:

    cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" -B bin .
    cmake --build .
    cmake --build . --target install   # optional

Do not use sudo or Run As Administrator for cmake in general.

Note that on Windows, CMake defaults make to Visual Studio and Nmake. The cmake options above direct the build to MinGW.

sh.exe error with cmake

I get a nuisance error from cmake about sh.exe being on the Path:

sh.exe was found in your PATH, here: C:/Program Files/Git/user/bin/sh.exe For MinGW make to work correctly sh.exe must NOT be in your path. Run cmake from a shill that does not have sh.exe in your PATH. If you want to use a UNIX shell, then use MSYS Makefile

Eliminate this message by adding -DCMAKE_SH="CMAKE_SH-NOTFOUND" to the cmake command, like:

cmake -G "MinGW Makefiles" -DCMAKE_SH="CMAKE_SH-NOTFOUND" ..