首页 > 解决方案 > vscode cpp build tasks.json 类型:“cppbuild”错误

问题描述

VSCode:1.61.0
Linux:Ubuntu 20.04.3 LTS

我正在尝试使用 VSCode 构建 c++ 程序。运行构建时,VSCode 显示此消息。

我知道构建任务需要将 launch.json 文件的 preLaunchTask 与 tasks.json 文件的标签匹配。我已经设置好了。

任务.json

{
    "tasks": [
        {
            "type": "cppbuild", // but "shell" is working
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/g++",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

启动.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++ - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++ build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

问题是,如果我将 tasks.json 中的“类型”值从 shell 更改为 cppbuild,它就不起作用并显示错误消息。

运行构建时显示错误消息

“cppbuild”和“shell”有什么不同?以及我应该如何使用“cppbuild”值?

标签: visual-studio-code

解决方案


推荐阅读