linux - Visual Studio 代码调试器错误 : "Could not find the task ' gcc build active file'

标签 linux visual-studio-code vscode-debugger

我正在尝试使用 Ubuntu Linux 在 Visual Studio Code 中配置 C/C++ 工作区,但我不知道如何使调试器正常工作。我从互联网上复制了一个“tasks.json”文件,以便能够通过按下 F5 来编译我的代码,但我认为它会导致调试器出现某种问题,因为每次我尝试进入 Debug模式时,都会出现错误“Could找不到任务“gcc 构建事件文件”弹出。
这是2个jsons:
任务文件

{
"version": "2.0.0",
"tasks": [
    {
        "label": "debug",
        "type": "shell",
        "command": "",
        "args": [
            "g++",
            "-g",
            "${relativeFile}",
            "-o",
            "a.exe"
        ]
    },
    {
        "label": "Compile and run",
        "type": "shell",
        "command": "",
        "args": [
            "g++",
            "-g",
            "${relativeFile}",
            "-o",
            "${fileBasenameNoExtension}.out",
            "&&",
            "clear",
            "&&",
            "./${fileBasenameNoExtension}.out"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        },
        "problemMatcher": {
            "owner": "cpp",
            "fileLocation": [
                "relative",
                "${workspaceRoot}"
            ],
            "pattern": {
                "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                "file": 1,
                "line": 2,
                "column": 3,
                "severity": 4,
                "message": 5
            }
        }
    },
    {
        "type": "shell",
        "label": "g++ build active file",
        "command": "/bin/g++",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "/bin"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": "build"
    }
]

}

启动文件
{
// 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": "(gdb) Launch",
        "type": "cppdbg",
        "request": "launch",
        "program": "enter program name, for example ${workspaceFolder}/a.out",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ]
    },
    {
        "name": "gcc build and debug active file",
        "type": "cppdbg",
        "request": "launch",
        "program": "${fileDirname}/${fileBasenameNoExtension}",
        "args": [],
        "stopAtEntry": false,
        "cwd": "${workspaceFolder}",
        "environment": [],
        "externalConsole": false,
        "MIMode": "gdb",
        "setupCommands": [
            {
                "description": "Enable pretty-printing for gdb",
                "text": "-enable-pretty-printing",
                "ignoreFailures": true
            }
        ],
        "preLaunchTask": "gcc build active file",
        "miDebuggerPath": "/usr/bin/gdb"
    }
]

}

在此先感谢您的帮助,我真的很无能为力。

最佳答案

在您的 task.json文件,没有任务被标记为“gcc 构建事件文件”,这是 preLaunchTask 所必需的在 launch.json文件。

因此,您可以更改 label任务或更改preLaunchTask的内容使它们匹配。

只需更改preLaunchTask的内容即可进入“g++ 构建事件文件”。它会起作用。

关于linux - Visual Studio 代码调试器错误 : "Could not find the task ' gcc build active file',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59106732/

相关文章:

linux - 构建 glibc 时出错

linux - 无法构建 ORBIT2 : fix apparently found but where is it?

linux - 使用 Expect 填写多行提示

git - 为什么我在 VsCode git 中有两个源代码控件?

linux - Linux Xwindow 转发上的 Visual Studio Code

typescript - 无法在 TypeScript 中调试 - VS Code

visual-studio-code - 无法通过 VS Code 运行 python 代码。无法打开文件 ptvsd_launcher.py [Errno 22] 无效参数

c - C中fork的子进程是前台还是后台

visual-studio-code - 在 vscode 中恢复已保存文件的先前版本

node.js - 无法使用 'autoAttachChildProcesses' 调试 fork 进程