返回> 网站首页 

ubuntu使用VSCode编译Makefile、调试C++程序

yoours2023-03-10 13:08:08 阅读 1291

简介一边听听音乐,一边写写文章。

        保留原有程序使用Makefile编译的方法,使用VSCode调试代码。


一、根据需要安装插件

        

二、配置文件

    配置文件在每个工程文件夹下的 .vscode 中,包含:launch.json、tasks.json 等。

    1. launch.json 文件内容如下:

{

    "version": "0.2.0",

    "configurations": [

        {

            "name": "(gdb) Launch",          //启动配置的下拉菜单中显示的名称

            "type": "cppdbg",

            "request": "launch",    // 请求配置类型,可以为launch(启动)或attach(附加)

            "program": "${workspaceFolder}/Server/bin/Server.bin",   // 将要进行调试的程序的路径

            "args": [],

            "stopAtEntry": false,    // 设为true时程序将暂停在程序入口处

            "cwd": "${workspaceFolder}/Server/bin/",   // 调试程序时的工作目录

            "environment": [],

            "externalConsole": true,  // 调试时是否显示控制台窗口

            "MIMode": "gdb",

            "setupCommands": [

                {

                    "description": "Enable pretty-printing for gdb",

                    "text": "-enable-pretty-printing",

                    "ignoreFailures": true

                }

            ],

            "preLaunchTask": "build-debug"                        // 调试会话开始前执行的任务,一般为编译程序

        }

    ]

}

    2. tasks.json文件内容如下:
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "command": "make",
            "type": "shell"
        },
        {
            "label": "build-debug",
            "command": "make",
            "args": ["debug"],
            "type": "shell",
            "dependsOn": [
                "clean",    // 在编译之前先清除旧的编译文件
            ]
        },
        {
            "label": "clean",
            "command": "make",
            "args": ["clean"],
            "type": "shell"
        }
    ]
}

三、使用

        

        点击绿色三角开始清理工程、编译、运行,设置断点即可调试。


微信小程序扫码登陆

文章评论

1291人参与,0条评论