在vscode下创建tasks.json文件,该文件会被vscode用来执行生成可执行文件的操作。
{
"version": "2.0.0",
"tasks": [
{
"label": "build c",
"type": "shell",
"command": "cc",
"args": [
"-std=c99",
"-Wall",
"-ledit",
"-lm",
"-g",
"${workspaceFolder}/**.c",
"-o",
"${workspaceFolder}/${fileBasenameNoExtension}.out"
],
"group": "build"
},
]
}
Command 和 args 是主要的参数,如何生成可执行文件就如何编写。
${workspaceFolder}表示工作目录
${fileBasenameNoExtension}如其名表示去掉后缀的文件名
创建launch.json文件,该文件会被vscode用来执行debug操作。
{
"version": "0.2.0",
"configurations": [
{
"preLaunchTask": "build c",
"name": "Launch C",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "lldb",
}
]
}
preLaunchTask填写生成调试文件的task的label。
两个文件设置完之后,在vscode侧边栏的run and debug窗口中就可以进行调试。
更多参数以及使用详见https://code.visualstudio.com/docs/editor/debugging#_launch-configurations