一. 在.vscode下建两个文件
1.1. tasks.json:配置编译
1.2. lunch.json配置debug
PS:附录中我提供源文件
二. 创建makefile,以便json调用
三. build
3.1. 打开源码文件
3.2. 编译
点击菜单上Terminal->config Task->make build
3.2. clean
点击菜单上Terminal->config Task->clean
四. Debug
4.1. 按F5开始debug(或按菜单上的Run)
4.2. 设置断点(在行前左击)
4.3. 如果运行时不执行断点,报信息如下
4.3.1. Module containing this breakpoint has not yet loaded or the breakpoint address not be obtained
如果你编译没有加-g时,调试就会出现这个信息
五. 附录
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" } ] }