前置条件:
1.vscode安装C/C++ Extension Pack扩展
2.安装gcc或者clang开发环境
在工程.vscode目录下创建task任务文件
tasks.json
{"tasks": [{"type": "cppbuild","label": "build","command": "/usr/bin/clang","args": ["-fcolor-diagnostics","-fansi-escape-codes","-g","main.c","-o","${cwd}/main"],"options": {"cwd": "${cwd}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "调试器生成的任务。"}],"version": "2.0.0"
}
其中"command": "/usr/bin/clang",可以换成对应的c编译器,比如gcc
在工程.vscode目录下创建运行文件
launch.json
{"version": "0.2.0","configurations": [{"name": "run","type": "cppdbg","request": "launch","program": "${cwd}/main","args": [],"stopAtEntry": false,"cwd": "./","environment": [],"externalConsole": false,"MIMode": "lldb"}]
}
"program": "${cwd}/main", main为task任务中编译后的-o输出文件
"MIMode": "lldb",选择对应的c调试器,比如gdb
运行步骤:
1. 依次选择菜单 <终端> ----- <运行任务> ,任务名对应task中的label值;
2. 依次选择菜单 <运行> ----- <启动调试> ,可以对源码打断点调试;