windows--cmake与c++的使用教程(5)

1 概述

本节目标: 关于cmake脚本错误处理 及cmake脚本执行流程

2 错误提示

  • 当脚本语法出错时,cmake会输出 错误位于哪个文件、第几行、以及错误原因。
  • 下面,将演示 使用message输出 hello cmake出错。

3 错误脚本

  • 脚本内容, 错误:message"没有配对
cmake_minimum_required(VERSION 3.20)
# 项目名称
project(cmake_library)
# 输出hello cmake
message("hello cmake)

5 构建脚本

  • 使用 ctrl + shift + p 打开命令行, 键入以下命令,回车。
> cmake: configure

用的多了,VScode会将常用的cmake命令放在最前面。

6 处理错误

  • 错误输出
[cmake] CMake Error at CMakeLists.txt:5:
[cmake]   Parse error.  Function missing ending ")".  Instead found unterminated
[cmake]   string with text "hello cmake)".
[cmake] 
[cmake] 
[cmake] -- Configuring incomplete, errors occurred!
  • 错误提示:直接定位到具体的文件,第几行。 对应这里的错误就是CMakeLists.txt文件,第五行。错误定位很准确。

7 修改

  • 将Message的括号匹配即可
message("hello cmake")

8 CMake脚本执行顺序

  • 从CMakeLists.txt中从上向下依次执行

9 使用VSCode打开文件夹

  • 使用VScode打开CMakeLists.txt所在文件夹方可执行>cmake: configure语法构建cmake脚本
posted @ 2022-11-15 23:18  mohist  阅读(589)  评论(0编辑  收藏  举报