最近在使用VSCode编译C++时遇到了一个问题,按F5运行时提示如下:
文字版提示为:
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/launch.json和vscode/tasks.json文件
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "cpp.exe - 生成和调试活动文件", //⭐cpp改为g++
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false, //⭐false改为true
"MIMode": "gdb",
"miDebuggerPath": "D:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "cpp" //⭐cpp改为g++
}
]
}
{
"version": "2.0.0",
"command": "cpp", //⭐cpp改为g++
"type": "shell",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
"args": ["-g", "${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
参考链接:
https://blog.csdn.net/qq_15054345/article/details/105173459
https://blog.csdn.net/weixin_41565755/article/details/104011031
https://blog.csdn.net/knight20160302/article/details/82953868?utm_medium=distribute.pc_relevant.none-task-blog-title-10&spm=1001.2101.3001.4242
https://victor.blog.csdn.net/article/details/105720511?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-4.channel_param