一. 在.vscode下建两个文件

     1.1. tasks.json:配置编译

     1.2. lunch.json配置debug 

           PS:附录中我提供源文件

VS code配置编译及debug环境

 

二.   创建makefile,以便json调用

三.  build

        3.1. 打开源码文件

        3.2. 编译

                 点击菜单上Terminal->config Task->make build

       3.2. clean

                 点击菜单上Terminal->config Task->clean

VS code配置编译及debug环境

 

 四. Debug

    4.1. 按F5开始debug(或按菜单上的Run)

    4.2. 设置断点(在行前左击)

VS code配置编译及debug环境

 

     4.3. 如果运行时不执行断点,报信息如下

         4.3.1. Module containing this breakpoint has not yet loaded or the breakpoint address not be obtained

                如果你编译没有加-g时,调试就会出现这个信息

VS code配置编译及debug环境

 五. 附录

    5.1. tasks.json

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "make build",
            "command": "/usr/bin/make",
            "args": [
                "all"
            ],
            "type": "shell",
            "problemMatcher": [],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        },
        {
            "label": "clean",
            "command": "/usr/bin/make",
            "args": [
                "clean"
            ],
            "type": "shell"
        },
        {
            "type": "shell",
            "label": "gcc build",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/main"
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": "build"
        }
    ]
}
View Code

相关文章:

  • 2021-12-26
  • 2021-11-09
  • 2021-12-26
  • 2021-08-24
  • 2021-11-04
  • 2021-10-10
猜你喜欢
  • 2021-06-07
  • 2021-08-07
  • 2021-06-26
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-05-30
相关资源
相似解决方案