vscode+cmake 配置touch.json和tasks.json进行程序调试

本文主要是一个配置参考范例:

1、程序的目录结构:

2、CMakeLists.txt:重要的是set语句,编译成debug模式

cmake_minimum_required(VERSION 3.0)

project(SOLIDER)

include_directories(${CMAKE_SOURCE_DIR}/include)

add_compile_options(-std=c++11 -Wall)

set(CMAKE_BUILD_TYPE "Debug")

add_executable(solider_cmake main.cpp src/Gun.cpp src/solider.cpp)

3、主目录新建build文件夹,cmake操作在build文件夹中进行;

4、主要参数:(1)program:指向要调试程序的绝对路径;(2)preLaunchTask:指示在调试之前先执行哪些命令,和tasks.json中相关;

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/solider_cmake",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                },
                {
                    "description": "将反汇编风格设置为 Intel",
                    "text": "-gdb-set disassembly-flavor intel",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask":"Build",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

tasks.json:包含了三个任务,第一个任务执行cmake,第二个任务执行make,第三个任务名称是Build,执行cmake和make两个任务,将Build设置成launch.json中preLaunchTask的值,正是代表,在调试之前先执行cmake和make两个命令;

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "options": {
        "cwd":"${workspaceFolder}/build"
    },
    "tasks": [
        {
            "label": "cmake",
            "type": "shell",
            "command": "cmake",
            "args":[
                ".."
            ]
        },
        {
            "label":"make",
            "group":{
                "kind": "build",
                "isDefault": true
            },
            "command":"make",
            "args": [

            ]
        },
        {
            "label":"Build",
            "dependsOrder": "sequence",
            "dependsOn":[
                "cmake",
                "make"
            ]
        }
    ]
}

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小米的修行之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值