首页 > 其他分享 >构建简单CMake及vscode调试

构建简单CMake及vscode调试

时间:2023-06-14 14:44:06浏览次数:51  
标签:cmake vscode Build workspaceFolder CMake type cwd 调试

main.cpp

#include <iostream>

int main()
{
    int num_a, num_b;
    num_a = 10;
    num_b = 20;
    std::cout << "num_a = " << num_a << std::endl;
    std::cout << "num_b = " << num_b << std::endl;
    return 0;
}
View Code

CMakeLists.txt

cmake_minimum_required(VERSION 3.10)

project(cmake_debug)

add_executable(cmake_debug main.cpp)
View Code

tasks.json

{
    "version": "2.0.0",
    "tasks": [
        // 1. cmake 配置
        {
            "type": "cppbuild",
            "label": "CMake: 配置",
            "command": "cmake",
            "args": [
                "-DCMAKE_BUILD_TYPE=Debug",
                "-S .",
                "-B Build"
            ],
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "cwd": "${workspaceFolder}"
            }
        },
        // 2. cmake 构建
        {
            "type": "cppbuild",
            "label": "CMake: 构建",
            "command": "cmake",
            "args": [
                "--build",
                "Build"
            ],
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "dependsOn": [
                "CMake: 配置"
            ]
        },
        // 3. 删除Build目录
        {
            "type": "shell",
            "label": "删除Build目录",
            "command": "rm",
            "args": [
                "-rf",
                "Build"
            ],
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "cwd": "${workspaceFolder}"
            }
        },
        // 4. 运行可执行文件
        {
            "type": "shell",
            "label": "运行可执行文件",
            "command": "./Build/cmake_debug",
            "problemMatcher": "$msCompile",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "dependsOn": [
                "CMake: 构建"
            ]
        }
        
    ]
}
View Code

launch.json

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "C++ CMake Debug",
            "program": "${workspaceFolder}/Build/cmake_debug",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "CMake: 构建"
        }
    ]
}
View Code

 

标签:cmake,vscode,Build,workspaceFolder,CMake,type,cwd,调试
From: https://www.cnblogs.com/xiaoruirui/p/17480185.html

相关文章

  • VSCode - Replace Tab with Spaces
    PressF1.Input'indentationtospaces'.SetaKeyBindingtothecommand'ConvertIndentationtoSpaces':Exitandre-openVSCodetomakethesettingtakeeffect.......
  • linux GDB高级调试
    gdb-v查看版本 CppCon2015:GregLaw'Giveme15minutes&I'llchangeyourviewofGDB'       https://undo.io/resources/cppcon-2015-greg-law-give-me-15-minutes-ill-change/视频不行可以看下面说明gcc-ghello.c-ogdba.out ctrl+x+actrl......
  • Cmake 基础教程
    介绍CMake是个一个开源的跨平台自动化建构系统,用来管理软件建置的程序,并不依赖于某特定编译器,并可支持多层目录、多个应用程序与多个库。它用配置文件控制建构过程(buildprocess)的方式和Unix的make相似,只是CMake的配置文件取名为CMakeLists.txt。CMake并不直接建构出最终的软件,......
  • Log in Leetcode in Vscode With Cookies" #标题
    Installleetcodeplug-ininvscodeIt'seasybysearchinExtension.LoginwithcookiesIfyouwanttologinleetcodeinvscodeleetcodeplug-inbygithubaccount,theremaybebugsthatyoucan'ttestorsubmit.Butifyousigninwithcookies......
  • Cmake之 target_include_directories
    target_include_directories是CMake中用于指定目标(target)的头文件搜索路径的命令。它的语法如下:target_include_directories(target[SYSTEM][BEFORE]<INTERFACE|PUBLIC|PRIVATE>[items1...][<INTERFACE|PUBLIC|PRIVATE>[items2...]...]) 其中,`t......
  • VMWare+Ubuntu+VsCode+C环境配置
    昨天整个流程走了四次,我现在已经是虚拟机战士了TT一、下载VMWareStation,打开一个新虚拟机,网络设置选NAT二、到Ubuntu官网下载iso映像文件,虚拟机就使用这个映像。    建议到官网下载最新版本22.04LTS,我用旧版本老是各种出错!!!    Ubuntu系统下载|Ubuntu三、......
  • 在使用VScode编辑器vue开发过程中,v-for在Eslint的规则检查下出现报错:Elements in iter
    报错如下: 该怎么解决呢?现在说说解决他的两种方法:1.直接在v-for循环后面绑定一个属性,跟前面需要循环的属性一一对应,截图如下:  2.在vscode中去掉Eslint规则检查,具体操作截图如下:文件–》首选项–》设置–》在搜索框中输入:vetur.validation.template,找到之后将前面的打钩......
  • 工作中遇到的问题1--IDEA调试端口占用问题
    Unabletoopendebuggerport(127.0.0.1:62169):java.net.BindException"Addressalreadyinuse:NET_Bind"调试的时候其实是新开的,然后报这个问题,当然自己也知道肯定是端口被占用了,有一种方式就是去查端口被哪个进程占用,然后杀掉即可,但是不想用这种方法netstat-aon|finds......
  • Pycharm配置远程调试
    原文链接在搞深度学习的时候,我们在本地开发,但是需要在服务器去运行工程,所以需要使用Pycharm进行远程配置,可以实现本地代码自动同步到服务器,并在本地使用服务器的解释器。条件:需要使用专业版Pycharm。远程部署点击菜单栏Tools——Deployment——Configuration点“+”,新建一个......
  • Pycharm配置远程调试
    原文链接在搞深度学习的时候,我们在本地开发,但是需要在服务器去运行工程,所以需要使用Pycharm进行远程配置,可以实现本地代码自动同步到服务器,并在本地使用服务器的解释器。条件:需要使用专业版Pycharm。远程部署点击菜单栏Tools——Deployment——Configuration点“+”,新建一个S......