How to solve “Could not find the task 'gcc build active file.” error in VSCode?

丶灬走出姿态 提交于 2020-07-03 08:19:09

问题


I've just setup VSCode to work from home with my remote SSH that runs Gentoo x64. Everything works fine apart from the GCC debugger which we usually use. It throws me the error in the title.

Here's my launch.json:

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

and my tasks.json:

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

And yes, I do compile with the -g flag. Any ideas on how to fix this?


回答1:


You will need to add gdb configuration:

In the debug menu, left side, click the debug icon, in the top you have a drop down menu where you have you default config "gcc build active file", you will need to click that and select "add configuration", select (gdb) Launch, this will add to the launch.json something along the lines of:

    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/a.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\TDM-GCC-64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]

Of course mine is windows so yours will be different.

You might have to configure the name of the executable, working folder, gdb location, etc.

Then in the same dropdown menu select (gdb) Launch



来源:https://stackoverflow.com/questions/61192212/how-to-solve-could-not-find-the-task-gcc-build-active-file-error-in-vscode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!