为什么tasks.json:无法识别文件格式

liw*_*eng 4 format compiler-errors visual-studio-code vscode-tasks

我在 ubuntu16 上运行 VScode,并测试 helloworld.cpp。一开始,我遍历了所有,然后我尝试编辑tasks.json。我得到了错误。好的,我用回滚取消了所有更改,它显示错误 aagin。我删除了 helloworld 文件夹,然后再试一次 helloworld。在终端 > 配置默认构建任务并构建后,错误再次显示。怎么了?它来自 vscode。

错误信息:

执行任务:/usr/bin/g++ -g /home/liwenz/helloworld/.vscode/tasks.json -o /home/liwenz/helloworld/.vscode/tasks <

/usr/bin/ld:/home/liwenz/helloworld/.vscode/tasks.json:文件格式无法识别;视为链接器脚本 /usr/bin/ld:/home/liwenz/helloworld/.vscode/tasks.json:1: 语法错误 collect2: 错误: ld 返回 1 退出状态终端进程以退出代码终止:1

任务文件

{
"version": "2.0.0",
"tasks": [
    {
        "type": "shell",
        "label": "C/C++: g++ build active file",
        "command": "/usr/bin/g++",
        "args": [
            "-g",
            "${file}",
            "-o",
            "${fileDirname}/${fileBasenameNoExtension}"
        ],
        "options": {
            "cwd": "${workspaceFolder}"
        },
        "problemMatcher": [
            "$gcc"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]
Run Code Online (Sandbox Code Playgroud)

}

helloworld 链接是https://code.visualstudio.com/docs/cpp/config-linux

小智 8

您必须从 tasks.json 文件切换到要编译或调试的实际代码。