task.json
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "task g++",
"command": "C:\\Environment\\mingw64\\bin\\g++.exe", //修改为自己路径
"args": [
"-g", //g++ -g
"${file}", //g++ -g main.cpp
"-o", //g++ -g main.cpp -o
"${fileDirname}\\${fileBasenameNoExtension}.exe" //g++ -g main.cpp -o main.exe
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "shared"
}
}
]
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true, //改为true
"preLaunchTask": "task g++", //新增项
"MIMode": "gdb",
"miDebuggerPath": "C:\\Environment\\mingw64\\bin\\gdb.exe", //MinGW位置
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
setting.json
{
"tabnine.experimentalAutoImports": true,
"editor.fontSize": 17,
"editor.renderWhitespace": "all",
"terminal.integrated.defaultProfile.windows": "Git Bash",
"terminal.integrated.profiles.windows": {
"Git Bash": {
"source": "Git Bash"
},
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"cmder":{ //使用 cmder 作终端
"path": "C:\\KcSoftware\\cmder\\vendor\\git-for-windows\\bin\\bash.exe",
"args":[]
},
},
}
F5 运行错误
> Executing task: C:\Environment\mingw64\bin\g++.exe -g d:\MyCodeSpace\VsCode\vscode-test\hello.cpp -o d:\MyCodeSpace\VsCode\vscode-test\hello.exe <
/usr/bin/bash: C:Environmentmingw64bing++.exe: command not found
终端进程“C:\Program Files\Git\bin\bash.exe '--login', '-c', 'C:\Environment\mingw64\bin\g++.exe -g d:\MyCodeSpace\VsCode\vscode-test\hello.cpp -o d:\MyCodeSpace\VsCode\vscode-test\hello.exe'”已终止,退出代码: 127。
原因
设置了默认 shell 为 git bash,注掉这一句调试正常,