windows下使用CMake,设置步骤

1.安装mingw-64

下载:https://sourceforge.net/projects/mingw-w64/files/latest/download
推荐默认路径安装(勾选 添加到环境变量,重启生效)

2.安装CMake

下载:https://cmake.org/files/
推荐默认路径安装(勾选 添加到环境变量,重启生效)

3.修改cmake在mingw下的工具

在路径下C:\Program Files\mingw-w64\x86_64-8.1.0-posix-seh-rt_v6-rev0\mingw64\bin找到mingw32-make.exe文件复制一份重命名为make.exe
windows下使用CMake,设置步骤_第1张图片
若出现此错误:注意第三步。。。make : 无法将“make”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路 径,请确保路径正确,然后再试一次。

4. 在cmd中使用cmake

  1. 每次cmake之前删除缓存
  2. cd build
  3. cmake -G "Unix Makefiles" ../ (非常重要)

常见错误提示

  1. – Building for: NMake Makefiles
    – The C compiler identification is GNU 8.1.0
    – The CXX compiler identification is GNU 8.1.0
    – Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe
    CMake Error: Generator: execution of make failed. Make command was: nmake /nologo cmTC_356da\fast &&
    – Check for working C compiler: C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe – broken
    CMake Error at C:/Program Files/CMake/share/cmake-3.15/Modules/CMakeTestCCompiler.cmake:60 (message):
    The C compiler
    “C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe”
    is not able to compile a simple test program.
    It fails with the following output:
    Change Dir: C:/cpp/XXX/build/CMakeFiles/CMakeTmp
    Run Build Command(s):nmake /nologo cmTC_356da\fast && 系统找不到指定的文件。
    Generator: execution of make failed. Make command was: nmake /nologo cmTC_356da\fast &&
    CMake will not be able to correctly generate this project.
    Call Stack (most recent call first):
    CMakeLists.txt:10 (project)
    – Configuring incomplete, errors occurred!
    See also “C:/cpp/XXX/build/CMakeFiles/CMakeOutput.log”.
    See also “C:/cpp/XXX/build/CMakeFiles/CMakeError.log”.
解决办法:看第四步 4. 在cmd中使用cmake

你可能感兴趣的:(Windows各种疑难杂症)