vscode配置task.json和launch.json启动调试

首先说一下参考博文:

文章标题“VScode 调试教程 tasks.json和launch.json的设置(超详细)
地址:https://blog.youkuaiyun.com/qq_59084325/article/details/125662393

官方文档太官方,其他人的文档也看过,单独都理解了,两个配置搭配就是没能启动调试,原来是相对路径的问题,今天看了一个超详细图片说明,加上C/C++的编译和使用的时间长了一点,就可以配置并调试了。


linux下的环境

  1. launch.json用于调试的启动,多个配置在启动处有下拉列表的
  2. task.json是编译配置,launch之前先自动编译

举例,配置两个调试
task.json

{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "build rgba_to_yuv420.c",
            "command": "/usr/bin/gcc",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${fileDirname}/rgba_to_yuv420.c",
                "-I.",
                "-Iinclude",
                "-Llib",
                "-lyuv",
                "-o",
                "test-rgba_to_yuv420"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        },
        {
            "type": "cppbuild",
            "label": "build NV12 OVERLAY",
            "command": "/usr/bin/g++",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${fileDirname}/pixel_format_nv12_overlay.cpp",
                "${fileDirname}/pixel_format_nv12_overlay-test.cpp",
                "${fileDirname}/rgb_to_nv12.cpp",
                "-I.",
                "-o",
                "test-nv12_overlay"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

task.json主要就是配置编译命令。


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": [
        {
            "type": "cppdbg",
            "request": "launch",
            "name": "Debug rgba_to_yuv420",
            "program": "${workspaceFolder}/test-rgba_to_yuv420",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "build rgba_to_yuv420.c",
            "MIMode": "gdb"
        },
        {
            "type": "cppdbg",
            "request": "launch",
            "name": "Debug NV12 overlay",
            "program": "${workspaceFolder}/test-nv12_overlay",
            "args": [],
            "cwd": "${workspaceFolder}",
            "preLaunchTask": "build NV12 OVERLAY",
            "MIMode": "gdb"
        },
    ]
}

launch.json用于启动调试
在这里插入图片描述

配置文件中使用了内置变量,${fileDirname},${workspaceFolder}等等,因为涉及文件和路径,所以调试的时候注意相对路径

在上面两个配置文件中,workspaceFolder${fileDirname}的实际路径是一致。
源代码文件都位于项目的根目录。

在这里插入图片描述

所以调试启动时,当前打开文件或者左侧目录树中选中的文件需要是项目跟目录文件,才能正确启动编译和调试。

两个文件要相互依赖
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值