需要修改launch.json和tasks.json文件
第一步修改launch.json文件
修改miDebuggerPath ,修改你自己系统中gdb所在位置,window中vscode修改同理
下面是我Ubuntu中修改(使用which gdb可以找到文件所在)
"miDebuggerPath": "/usr/bin/gdb"
第二步修改task.json文件
找到type,值全部修改为shell
"type": "shell",
command如有错误,同样需要修改为gcc/g++的文件路径
launch.json和tasks.json文件如下,可对照查看
{
"configurations": [
{
"name": "C/C++: g++ 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ 生成活动文件",
"miDebuggerPath": "/usr/bin/gdb"
},
{
"name": "C/C++: gcc 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc 生成活动文件",
"miDebuggerPath": "/usr/bin/gdb"
}
],
"version": "2.0.0"
}{
"tasks": [
{
"type": "shell",
"label": "C/C++: gcc 生成活动文件",
"command": "/usr/lib/ccache/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
//"${file}",
".cpp",
"-o",
//"${fileDirname}/${fileBasenameNoExtension}"
"${fileDirname}/a.out"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。"
},
{
"type": "shell",
"label": "C/C++: g++ 生成活动文件",
"command": "/usr/lib/ccache/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
//"${file}",//取消注释改行和注释下行可运行单个cpp文件
".cpp",
"-o",
//"${fileDirname}/${fileBasenameNoExtension}"//取消注释改行和注释下行可运行单个cpp文件
"${fileDirname}/a.out"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "调试器生成的任务。"
},
{
"type": "cppbuild",
"label": "C/C++: g++-11 生成活动文件",
"command": "/usr/lib/ccache/g++-11",
"args": [
"-fdiagnostics-color=always",
"-g",
//"${file}",
"*.cpp",
"-o",
//"${fileDirname}/${fileBasenameNoExtension}"
"${fileDirname}/a.out"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"