在Windows上使用CMake构建项目出现了很多错误,搜索了很多资料尝试改了很多地方始终没能找到与我类似的情况,一度让我以为是系统问题。今天发现就一句,是没用cmake -G"Unix Makefiles" 的问题。

1.在CMakelists文件中设置了以下参数仍然无效

#SET(CMAKE_MAKE_PROGRAMC "C:/mingw64/bin/make.exe")
#SET(CMAKE_C_COMPILER "C:/mingw64/bin/gcc.exe")
#SET(CMAKE_CXX_COMPILER "C:/mingw64/bin/g++.exe")

如果不设置以上代码则会出现指定的C编译器未知。The C compiler identification is unknown

d:\clang-work1>cmake .. -G"NMake Makefiles"
CMake Error: The source directory "D:/" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.d:\clang-work1>cmake -G"NMake Makefiles" .
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown

2.CMake在windows下默认生成NMake Makefiles,用cmake -G"MinGW Makefiles" 则会出现以下错误原因未知。

D:\clang-work\clang-work>cmake -G"MinGW Makefiles" .
CMake Error: Error: generator : MinGW Makefiles
Does not match the generator used previously: NMake Makefiles
Either remove the CMakeCache.txt file and CMakeFiles directory or choose a different binary directory.D:\clang-work\clang-work>

3.直接用cmake . 则会出现以下错误

D:\clang-work\clang-work>cmake .
-- Building for: NMake Makefiles
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:7 (project):The CMAKE_C_COMPILER:clis 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 shellthat can use the compiler cl from the command line.  This environment isunable to invoke the cl compiler.  To fix this problem, run cmake from theVisual Studio Command Prompt (vcvarsall.bat).Tell CMake where to find the compiler by setting either the environmentvariable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path tothe compiler, or to the compiler name if it is in the PATH.CMake Error at CMakeLists.txt:7 (project):The CMAKE_CXX_COMPILER:clis 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 shellthat can use the compiler cl from the command line.  This environment isunable to invoke the cl compiler.  To fix this problem, run cmake from theVisual Studio Command Prompt (vcvarsall.bat).Tell CMake where to find the compiler by setting either the environmentvariable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full pathto the compiler, or to the compiler name if it is in the PATH.-- Configuring incomplete, errors occurred!
See also "D:/clang-work/clang-work/CMakeFiles/CMakeOutput.log".
See also "D:/clang-work/clang-work/CMakeFiles/CMakeError.log".

4.cmake … -G"NMake Makefiles"则会出现以下错误,与使用cmake . 错误一样。

d:\clang-work1>cmake -G"NMake Makefiles" .
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
CMake Error at CMakeLists.txt:7 (project):The CMAKE_C_COMPILER:clis 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 shellthat can use the compiler cl from the command line.  This environment isunable to invoke the cl compiler.  To fix this problem, run cmake from theVisual Studio Command Prompt (vcvarsall.bat).Tell CMake where to find the compiler by setting either the environmentvariable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path tothe compiler, or to the compiler name if it is in the PATH.CMake Error at CMakeLists.txt:7 (project):The CMAKE_CXX_COMPILER:clis 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 shellthat can use the compiler cl from the command line.  This environment isunable to invoke the cl compiler.  To fix this problem, run cmake from theVisual Studio Command Prompt (vcvarsall.bat).Tell CMake where to find the compiler by setting either the environmentvariable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full pathto the compiler, or to the compiler name if it is in the PATH.-- Configuring incomplete, errors occurred!
See also "D:/clang-work1/CMakeFiles/CMakeOutput.log".
See also "D:/clang-work1/CMakeFiles/CMakeError.log".d:\clang-work1>

5.只有使用cmake -G"Unix Makefiles"才会正确生成Makefile文件

E:\clang-work>cmake -G"Unix Makefiles"
CMake Warning:No source or binary directory provided.  Both will be assumed to be thesame as the current working directory, but note that this warning willbecome a fatal error in future CMake releases.-- The C compiler identification is GNU 8.1.0
-- The CXX compiler identification is GNU 8.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/mingw64/bin/gcc.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/mingw64/bin/c++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: E:/clang-workE:\clang-work>

6.使用cmake -G"MinGW Makefiles"也为正确,但昨天这么写却始终报错。不知是我写错了还是哪个地方没设置好已经不记得了。可能是重新开机了,可能是将mingw32-make.exe复制了一份改名为make.exe但我想应该不是。

初学CMake很多东西不懂,自己遇到问题时到网上搜到的资料很少,刚好这个问题得以解决有一点点经验就想贡献一点资料,不足之处请指正。

用CMake构建工程时 cmake -G“Unix Makefiles“ 的使用相关推荐

  1. QtCreator使用CMake构建项目时jom Error 2问题

    QtCreator使用MSVC编译环境构建项目时,会因为配置不正确出现jom: C:/-/- [cmTC_fe41e\fast] Error 2错误,这里记录一下我的解决办法和对此问题的理解,希望能帮 ...

  2. 使用cmake构建工程

    之前在linux下做项目的时候,都要自己手动的写Makefile来编译项目.后来,做Android jni开发后,发现Android studio默认的c/c++编译的工具是cmake,一开始对语法丝 ...

  3. 使用CMake构建/开始使用CMake

    Getting started with CMake 开始使用CMake CMake is a group of tools that allow to build, test, and packag ...

  4. Cmake构建_指定gcc/g++版本

    平时我们电脑上可能有多个编译器版本,可以通过设置CMAKE_C_COMPILE和CMAKE_CXX_COMPILER两个变量来设置我们的编译器路径 SET(CMAKE_C_COMPILER " ...

  5. (转)淘淘商城系列——使用maven构建工程时出现的错误

    http://blog.csdn.net/yerenyuan_pku/article/details/72690846 我觉得maven就他妈是一个傻逼,反正我是对它无语了.昨天刚刚使用maven构建 ...

  6. 淘淘商城第6讲——使用maven构建工程时出现的错误

    我觉得maven就他妈是一个傻逼,反正我是对它无语了.昨天刚刚使用maven构建完工程,都没有出现任何问题,而且运行也是没有任何问题的,妈蛋,今天把Eclipse开发工具一打开,就出现了错误,截图如下 ...

  7. 【CC3200】【eegRudp】使用CMake组织工程

    CMake简介 CMake 是一个跨平台的.开源的构建工具.cmake 是 makefile 的上层工具,它们的目的正是为了产生可移植的makefile,并简化自己动手写makefile时的巨大工作量 ...

  8. 使用 CMake 构建 LLVM

    使用 CMake 构建 LLVM 1. 介绍 2. 快速开始 3. 基本的 CMake 用法 4. 选项和变量 4.1 经常使用的 CMake 变量 4.2 特定于LLVM的变量 5. CMake C ...

  9. 《cmake practice》总结 | cmake的构建过程与基本指令

    cmake 〇.基本语法规则 0.1 变量 0.2 指令规则 0.3 基本构建过程 一.基本指令 1. PROJECT指令 2. SET指令 3. MESSAGE指令 4. ADD_EXECUTABL ...

最新文章

  1. phpHiveAdmin开发两个月记录
  2. 一个web.Config或app.Config自定义段configSections的示例
  3. c#,Winform同一系统中只运行一个实例。
  4. 【原创】rabbitmq-env.conf用户手册(翻译)
  5. 4G EPS 的网络协议栈
  6. 1111 Online Map (30 分)【难度: 一般 / 知识点: Dijkstra最短路】
  7. thinkphp-1
  8. python常用类型转换の方法
  9. elk系列5之syslog的模块使用
  10. Rancher Managed Network实践
  11. 阿里云短信验证码平台使用demo
  12. php漂浮广告代码,js 居中漂浮广告_广告代码
  13. 一款神仙接私活低代码平台,吊到不行(附源码)
  14. 瞬态抑制二极管有方向吗?
  15. bind9智能dns配置
  16. 网络抓包学MQTT物联网协议
  17. 【技术分享】Win10环境php安装seaslog扩展
  18. 美国空运专线 美国空运专线时效多久
  19. linux 默认路由 主机路由 网络路由
  20. hawk -- pacemaker web GUI

热门文章

  1. Android 网易云信获取图片,Android 网易云信集成(一)
  2. java 异常何时抛出_何时适合抛出异常?
  3. 再见Navicat!这个工具才是YYDS!
  4. 开源中国 Chrome 插件,你的好帮手~
  5. 缓存模式以及缓存的数据一致性
  6. IntelliJ IDEA 2019.3发布,饱受性能诟病的2019.2版本终于成为过去式
  7. 7 个显著提升编码效率的IntelliJ IDEA必备插件
  8. Spring Cloud Alibaba基础教程:使用Sentinel实现接口限流
  9. 在一台Mac上不同平台同时使用多个Git账号
  10. linux pfn,ARM Linux下的page和pfn之间转换的宏。