当前位置: 首页 > news >正文

CMake的使用方法

1 CMakeLists.txt编写

cmake_minimum_required(VERSION 3.12)project(djl_plm)set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -g")add_executable(simple simple.cpp)
add_executable(main main.cpp)include_directories(include)

相当于如下gcc命令:

g++ simple.cpp -std=c++17 -Iinclude -o simple -g

2 Cmake构建方法

根目录下创建build目录

mkdir build

进入build目录

cd build

执行cmake构建命令

cmake ..

执行make编译命令

make

注意:一旦代码被修改了,就需要重新构建

3 VScode 调试方法

task.json配置

{   "version": "2.0.0","options": {"cwd": "${workspaceFolder}/build"},"tasks": [{"type": "shell","label": "cmake","command": "cmake","args": [".."]},{"label": "make","group": {"kind": "build","isDefault": true},"command": "make","args": []},{"label": "Build","dependsOrder": "sequence", // 按列出的顺序执行任务依赖项"dependsOn":["cmake","make"]}]}

launch.json配置

{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [{"name": "C/C++: g++ build and debug active file","type": "cppdbg","request": "launch","program": "${workspaceFolder}/build/main",  //main:被调试的程序文件"args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}","environment": [],"externalConsole": false,"MIMode": "gdb","miDebuggerPath": "/usr/bin/gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true}],"preLaunchTask": "Build"}]
}

优点:按下F5即可调试,并且每次修改代码后不再需要手动cmake编译构建。

项目目录结构如下:

http://www.lryc.cn/news/370247.html

相关文章:

  • java面试整合全套
  • 贪吃蛇小游戏简单制作-C语言
  • Oracle数据库-重点信息查询方法
  • 【全开源】多平台租房系统源码(Fastadmin+ThinkPHP+Uniapp)
  • Pythond 的 corr函数
  • Fiddler 中文版 (强大的网络响应HTPP协议抓包工具)
  • 初出茅庐的小李博客之JSON格式介绍
  • Vue3相关语法内容,组件传值,事件监听,具名插槽。
  • Linux用户,用户组,所有者权限分配,sftp用户权限分配
  • iFlyCode:AI智能编程助手引领未来软件开发新趋势
  • 高低温测试发现文件被篡改
  • 高考真的不再重要了吗?
  • spring常用注解(八)@Async
  • B站画质补完计划(3):智能修复让宝藏视频重焕新生
  • Spring Cloud Stream整合RocketMQ
  • Web前端浪漫源码:编织梦想与爱的交织乐章
  • 【云岚到家】-day02-4-我的账户-实名认证
  • MySQL复习题(期末考试)
  • 利用DVWA演示文件上传漏洞获取网站shell权限(二)
  • Java---BigInteger和BigDecimal和枚举
  • mybatis数据批量更新
  • 自动驾驶#芯片-1
  • 【保姆级讲解下QT6.3】
  • windows安装conda
  • ubuntu设置GPU功率
  • [发布]嵌入式系统远程测控软件-基于Qt
  • 【数据结构】查找(顺序查找、二分查找、索引顺序查找、二叉排序树、平衡排序树、B树、B+树、哈希表)
  • 远程连接路由器:方法大全与优缺点解析
  • NI USB-6009 DAQ采集卡拆解
  • 详细分析Mysql临时变量的基本知识(附Demo)