【问题标题】:vscode report that the active file is not a C or C++ source file while building a c filevscode在构建c文件时报告活动文件不是C或C++源文件
【发布时间】:2022-01-18 08:59:34
【问题描述】:

vscode在编译c程序时报错。错误信息如下。

Cannot build and debug because the active file is not a C or C++ source file.
The terminal process failed to launch (exit code: -1).

任务配置文件如下。

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++ build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "/home/xxx/tmp/test/main.c"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

我在 /home/xxx/tmp/test 文件夹下有一个名为 main.c 的 c 文件,它是工作区文件夹。问题的原因可能是什么?

【问题讨论】:

    标签: visual-studio-code build


    【解决方案1】:

    正如 Sean McManus 的 this 回复中所见,您需要删除您的 tasks.json 中的所有 ${file} 引用,例如:

    "args": [
        "-g",
        "${file}",
        "-o",
        "${fileDirname}/${fileBasenameNoExtension}"
    ],
    "options": {
        "cwd": "${fileDirname}"
    }
    

    改成

    "args": [
        "-g",
        "test.cpp",
        "-o",
        "libs/test.o"
    ],
    "options": {
        "cwd": "${fileDirname}"
    }
    

    并将构建类型从 cppBuild 更改为 shell

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-17
      • 2023-03-23
      • 2019-09-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      相关资源
      最近更新 更多