Visual Studio代码调试器错误:“找不到任务'gcc构建活动文件'

问题描述 投票:0回答:1

我正在尝试使用Ubuntu Linux在Visual Studio Code中配置C / C ++工作区,并且我不知道如何使调试器正常工作。我从互联网上复制了一个“ tasks.json”文件,以便可以通过按F5来编译我的代码,但我认为它会导致调试器出现某种问题,因为每次我尝试进入调试模式时,都会出现错误“找不到任务“ gcc建立活动文件”弹出。这是2个json:task.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"
    }
]

}

感谢您的帮助,我真的很无能。

linux visual-studio-code vscode-debugger
1个回答
0
投票

您需要指定文件的路径和名称。当然,只有在二进制文件使用g标志进行编译时调试才可能(输出变得更重且压缩更少)。

  • launch.json将映射到二进制文件

    “程序”:“ $ {workspaceFolder} /a.out”,

  • task.json将涉及如何编译

    “ args”:[“-G”,“ $ {workspaceFolder} / *。cpp”,“ -o”,“ $ {workspaceFolder} /a.out”

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

如果无法通过vscode使用它,则可能要使用其他工具,例如GDB。GDB在Linux / VM和WSL中的Terminal中也可以很好地工作。

© www.soinside.com 2019 - 2024. All rights reserved.