Monday, 31 August 2020

How to Solve CMake was unable to find a build program corresponding to MinGW Makefiles

You may have a situation that requires you to use CMake to build a source code and then got hit with an error while executing a cmake command, which is something similar as shown below.

C:\SomeProject>cmake . -G "MinGW Makefiles"

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage

CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage

-- Configuring incomplete, errors occurred!

There are few possibilities that may lead to this

1. Mingw-w64 is not installed

Since the error message mentioned that it is not able to find "MinGW Makefiles". Which mean that there is a possibility that you have not installed it to your machine. So, you may want to download the installer from here http://mingw-w64.org/doku.php and install it.

2. Installed Mingw-w64 but still showing the same error message

Most likely due to the installer did not place the necessary Mingw-w64 information to the %PATH% Environment Variables. So, you are required to fill in the Mingw-w64's bin path manually. To navigate to the Environment Variables:

a) In your Windows Search, search for the following keyword "Environment Variables" and select "Edit the system environment variables".

b) When the window "System Properties" appeared. Click on the button "Environment Variables".

c) On the next window, under the System variables section, look for the variable named "Path". Select it and click the Edit button.

d) In the Edit environment variable window, click New button and fill in the bin path of the Mingw-w64. Depend on the settings that you have picked during the Mingw-w64 installation, the default location of the Mingw-w64 can either be in Program Files or Program Files (x86).

Some of the example location:
C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin
C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin
C:\Program Files (x86)\mingw-w64\i686-8.1.0-posix-dwarf-rt_v6-rev0\mingw32\bin

If you have multiple settings of Mingw-w64 installed, just pick 1 of the path based on the setting that you required. 

e) Once you are done, save your configured path by clicking on the Ok button to close the "Edit environment variable" window. On the "Environment variable" window, click Ok button to close the window.

If you have command prompt opened while editing the %PATH% Environment Variables, you are required to close them all and open up a new command prompt. This is due to the old command prompt caches the previous %PATH% settings.

This is all that you need to do and the error should no longer appear.





1 comment: