之前在vscode进行debug调试的时候就会发生这个问题,这个问题也是我找了几天百度也到现在才成功解决的
(图为网页随机找图截取,问题一样,我解决的时候已经没有这个提示了所也懒得改回来刻意截图了)
这个时候下面的终端也会有以下提示
Unable to start debugging. Program path '***.exe' is missing or invalid. GDB failed with message: "***.exe": not inexecutable format: File format not recognized This may occur if the process's executable was changed after the process was started, such as when installing an update. Try re-launching the application or restarting the machine.
遇到这个问题,就要去修改vscode下俩个json文件(task和launch)
先给出解决后的源代码:
Launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - Build and debug active file", //配置名称里cpp改为g++
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true, //推荐打开,这样输出结果会打印在cmd窗口
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", //注意一下调试器的路径,路径为gdb所在的位置
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file" //cpp改为g++,与tasks.json的label相对应
}
]
}
Task.json
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file", //cpp改为g++,任务名称,与launch.json的preLaunchTask相对应
"command": "g++.exe", // 要使用的编译器,建议使用g++
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
],
"version": "2.0.0"
}
参考链接:
https://blog.csdn.net/weixin_44578662/article/details/107768618