我读过这个错误是因为 launch.json 和 tasks.json 文件中的一些设置。所以我删除了它们并制作了新的,但它给出了相同的错误并且不会构建和调试。我如何解决它?
启动.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",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
任务.json:{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-posix-seh-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
最佳答案
如果您之前已经编译过代码并且已经创建了可执行 (*.exe) 文件,请通过 VS 代码文件资源管理器将其删除,然后再次尝试构建您的代码。
这就是问题所在,至少在我的情况下。 VS 代码无法删除可执行文件以创建新的可执行文件。
关于c++ - 错误 : "The preLaunchTask ' C/C++: g++. exe 构建事件文件'以退出代码 1 终止”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64519454/