简体   繁体   English

如何解决“找不到任务 C/C++:gcc 构建活动文件”。 VSCode 中的错误?

[英]How do I fix “Could not find the task C/C++: gcc build active file.” error in VSCode?

I am working on a C program in VSCode, and I am on Windows running Ubuntu 20.04 via Windows Subsystem for Linux (WSL 1.0). I am working on a C program in VSCode, and I am on Windows running Ubuntu 20.04 via Windows Subsystem for Linux (WSL 1.0). Everything was working fine for the last few weeks until today when I encountered the error message in the title of this post.过去几周一切正常,直到今天我在这篇文章的标题中遇到错误消息。 I will include both the tasks.json and launch.json below (both are in the.vscode folder).我将包括下面的两个tasks.json和launch.json(两者都在.vscode文件夹中)。

tasks.json file: tasks.json 文件:

{
"version": "2.0.0",
"tasks": [
    {
        "type": "cppbuild",
        "label": "C/C++: gcc build active file",
        "command": "/usr/bin/gcc",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "detail": "compiler: /usr/bin/gcc"
    }
]
}

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

In the terminal output, I receive the following message when trying to run a basic program:在终端 output 中,尝试运行基本程序时收到以下消息:

Error: The cppbuild task detection didn't contribute a task for the following configuration:
{
    "type": "cppbuild",
    "label": "C/C++: gcc build active file",
    "command": "/usr/bin/gcc",
    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
    ],
    "options": {
        "cwd": "${workspaceFolder}"
    },
    "problemMatcher": [
        "$gcc"
    ],
    "group": {
        "kind": "build",
        "isDefault": true
    },
    "detail": "compiler: /usr/bin/gcc"
}
The task will be ignored.

It turns out downgrading the C/C++ extension was the answer.事实证明,降级 C/C++ 扩展就是答案。 A recent update caused this issue to occur.最近的更新导致出现此问题。

instead of:代替:

"type": "cppbuild", “类型”:“cppbuild”,

it worked for me:它对我有用:

"type": "shell", “类型”:“外壳”,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM