CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage

一、报错描述:

用CMake构建c++程序时报错:

$ cmake .
-- Building for: NMake Makefiles
CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.


CMake Error at CMakeLists.txt:2 (project):
  Running

   'nmake' '-?'

  failed with:

   系统找不到指定的文件。


CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
-- Configuring incomplete, errors occurred!
See also "C:/Users/eren.luo/Desktop/test/CMakeFiles/CMakeOutput.log".

二、解决办法:

p.s. mingw64/bin和cmake已添加至环境变量中。

  1. 编译时把
cmake .

改为:

cmake -G "MinGW Makefiles" .
  1. 运行时使用:
mingw32-make.exe all

三、C++和cmake版本:

  1. cmake-3.23.1-windows-x86_64.msi
  2. mingw-w64-install.exe

系统:Windows 10

四、参考文章:

  1. Running CMake on Windows
  2. CMAKE_C_COMPILER CMAKE_CXX_COMPILER not set

你可能感兴趣的:(windows,c++,cmake)