Visual studio code debugger error : "Could not find the task 'gcc build active file'

23,688

Solution 1

In your task.json file, no task is labeled as 'gcc build active file' which is required as a preLaunchTask in launch.json file.

So you can either change the label of task or change the content of preLaunchTask to make them match.

Just change the content of preLaunchTask into "g++ build active file". It will work.

Solution 2

You need to specify path and names of files. Of course debug is only possible if the binary is compiled with g flag (output becomes heavier and less compressed).

  • launch.json would map to binary file

    "program": "${workspaceFolder}/a.out",

  • task.json would relate to how to compile

    "args": [ "-g", "${workspaceFolder}/*.cpp", "-o", "${workspaceFolder}/a.out"

https://www.youtube.com/watch?v=X2tM21nmzfk&app=desktop

If you can't make it work through vscode, you may want to use another tool like GDB. GDB also works great in Terminal in Linux/VM and maybe WSL.

Share:
23,688
Andy Vavilov
Author by

Andy Vavilov

Updated on July 20, 2022

Comments

  • Andy Vavilov
    Andy Vavilov almost 2 years

    Im trying to configure a C/C++ workspace in Visual Studio Code using Ubuntu Linux, and I don't know how to make the debugger work properly. I copied from the internet a 'tasks.json' file to be able to compile my code with pressing of F5 but I think it causes some sort of a problem with the debugger because every time I try to enter debugging mode, the error "Could not find the task 'gcc build active file' pops up. Here are the 2 jsons : tasks.json

    {
    "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"
        }
    ]
    

    }

    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": "(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"
        }
    ]
    

    }

    Thanks in advance for the help, I m realy really clueless.

  • SunDontShine
    SunDontShine about 3 years
    For clarity, I believe Albert is referring to the tasks.json file
  • Jonathan
    Jonathan almost 3 years
    They both match in my case and I still get this error, I just had to restart VS Code, more info here: stackoverflow.com/a/55107773/1689770