Windows下Cmake编译报错解决方案
报错:
1. Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:5 (PROJECT):
The CMAKE_C_COMPILER:
cl
is not a full path and was not found in the PATH.
To use the NMake generator with Visual C++, cmake must be run from a shell
that can use the compiler cl from the command line. This environment is
unable to invoke the cl compiler. To fix this problem, run cmake from the
Visual Studio Command Prompt (vcvarsall.bat).
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
报错实际就是在提示找不到C,C++编译器
花费了3个多小时在网上查了出来各种方法,结果没什么用,一通尝试花费半下午一样不能编译通过,
解决方案:安装最新MInGW,为cmake指定C,C++编译器位置
1.安装minGW
mingw下载地址
然后傻瓜式安装就行,我安装位置是C:\MinGW
2. 添加环境变量
将 C:\MinGW\bin 添加到path环境变量,在cmd窗口查看是否安装成功
C:\Users\lt>gcc --version
gcc (MinGW.org GCC Build-20200227-1) 9.2.0
Copyright (c) 2019 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
C:\Users\lt>g++ --version
g++ (MinGW.org GCC Build-20200227-1) 9.2.0
Copyright (c) 2019 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
3.为cmake指定编译器位置
我的源码目录:E:\Go\Src\CmakeTest
CmakeTest:
---main.cpp
---CMakeLists.txt
E:\Go\Src\CmakeTest>set CC=/c/MinGW/bin/gcc.exe
E:\Go\Src\CmakeTest>set CXX=/c/MinGW/bin/g++.ex
E:\Go\Src\CmakeTest>cmake .
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.26.28806.0
-- The CXX compiler identification is MSVC 19.26.28806.0
-- Check for working C compiler: E:/tool/Visual Studio/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: E:/tool/Visual Studio/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: E:/tool/Visual Studio/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: E:/tool/Visual Studio/VC/Tools/MSVC/14.26.28801/bin/Hostx64/x64/cl.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: E:/Go/Src/CmakeTest
E:\Go\Src\CmakeTest>
ok,问题解决,编译成功