Install GCC, GFortran, CMake and Make on Windows

1 minute read

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 make under the bin/ directory as mingw32-make.exe.
  3. For convenience, symlink make to mingw32-make:
    cd C:\mingw\bin
            
    mklink make.exe mingw32-make.exe
    
  4. install CMake

CMake on Windows

Within the project code directory, in general build programs that have CMakeLists.txt on Windows (and other operating systems) with:

cd build

cmake -G "MinGW Makefiles" ..

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 for Windows 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" ..

Notes

Leave a Comment