vscode配置C++报错unable to start debugging.unexpected GDB output from command

unable to start debugging.unexpected GDB output from command或preLaunchTask“g++”已终止,退出代码为1的可能解决方案
解决方案:文件目录不能存在中文
在这里插入图片描述
首先你要确定你是否已经添加全局变量
在这里插入图片描述

你要确定你的配置文件没有错误
launch,json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "task g++", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", //配置类型,只能为cppdbg
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false, //true显示外置的控制台窗口,false显示内置终端
"MIMode": "gdb",
"miDebuggerPath": "D:\\MinGw\\mingw64\\bin\\gdb.exe", //gdb的文件地址
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true,
}
],
"preLaunchTask": "task g++" //和tasks中label保持一致
}
]
}

task,json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{
"version": "2.0.0",
"tasks": [
{
"label": "task g++", //任务的名字,就是刚才在命令面板中选择的时候所看到的,可以自己设置
"type": "shell",
"command": "g++",
"args": [ //编译时候的参数
"-g", //添加gdb调试选项
"${file}",
"-o", //指定生成可执行文件的名称
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true //表示快捷键Ctrl+Shift+B可以运行该任务
},

}
]
}

如果都没错,那就是上面第一张图片中标红的原因——文件目录名中含中文,需要改成全英才行,因为是当都放在桌面,所以需要改变桌面存放文件的默认地址
在这里插入图片描述

在这里插入图片描述