c++ - 错误 : "The preLaunchTask ' C/C++: g++. exe 构建事件文件'以退出代码 1 终止”

标签 c++ json visual-studio-code compiler-errors

enter image description here
我读过这个错误是因为 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/

相关文章:

visual-studio-code - VSCode - 是否可以始终在顶部某处显示当前函数名称?

c++ - 在仅在某些情况下使用 decltype 的模板中实例化函数定义

javascript - RESTful JSON 端点应该以 .js 结尾吗? JSONP 怎么样?

java - 将数组反序列化为自定义列表实现的 Jackson 全局设置

java - jquery 在 post 请求上发送表单数据,但是当我修改 servlet 以返回 json 并修改 jquery 以接受 json servlet 时未接收 null

visual-studio-code - vscode 的launch.json 有什么文档吗?我发现的内容已过时/丢失

c++ - 对流使用 unique_ptr 有意义吗?

c++ 类及其布局和转换

c++ - 如何迭代列表并从中删除?

Linux 和 Visual Studio 代码 : super + e