task.json
https://code.visualstudio.com/docs/editor/tasks
{
"tasks":
[{
"label": "Build", // 与launch preLaunchTask一致
"type": "shell", // shell命令
"request": "launch", // launch(启动)或 attach(附加)
"command": "g++", // 命令是g++
"args": [
"-g",
"'${file}'", // 当前文件名
"-o", // 对象名,不进行编译优化
"'${fileBasenameNoExtension}'", //当前文件名(去掉扩展名)
],
"options":{
"cwd": "${workspaceFolder}" //current working directory
// env (environment variables)
// shell (default shell)
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [
"$gcc" // 使用gcc捕获错误
],
}]
}
lanuch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Build",
"preLaunchTask": "Build", //tasks.json任务名一致
"type": "cppdbg",
"request": "launch",
"program": "${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false, // 暂时不执行程序
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}