0

When building with cmake on windows using Mingw64 we get errors like:

System cannot find the file specified

Log:

$ cmake ..
-- Building for: NMake Makefiles
CMake Error at CMakeLists.txt:72 (project):
  Running

   'nmake' '-?'

  failed with:

   The system cannot find the file specified


CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "E:/MyTools/C/libs_download/cpp-httplib-0.11.2/build/CMakeFiles/CMakeOutput.log".

How to fix it?

  • The **first error message** is searched relatively easy. It means that CMake attempts to use `NMake Makefiles` generator but there is no `nmake` installed in your system. That is, you need to choose another generator (or install nmake). – Tsyvarev Oct 10 '22 at 21:28
  • Yes, I figured it out :P I basically answered my own question. – Cypherpunk Samurai Oct 10 '22 at 22:07

1 Answers1

0

This happens because cmake uses the Microsoft CMake format as default. The CMAKE_CXX_COMPILER not set here also indicates that we need to set the CMAKE_CXX_COMPILER variable to a c++ compiler path.

To fix we need to use the following command:

cmake -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CC_COMPILER=gcc -DCMAKE_MAKE_PROGRAM=mingw32-make -G "MinGW Makefiles" ..

Here we provide the following flags:

  • CMAKE_CXX_COMPILER=g++ - Use g++ as C++ compiler (or provide full path)
  • CMAKE_CC_COMPILER=gcc - Use gcc as C compiler
  • CMAKE_MAKE_PROGRAM=mingw32-make - Use mingw32-make as the make program
  • -G "MinGW Makefiles" - Use the MinGW Makefile format not Microsoft makefile format

After this you can run mingw32-make as usual instead of make to build :)