【问题标题】:vscode tasks.json 2.0 g++ no such file or directoryvscode tasks.json 2.0 g++ 没有这样的文件或目录
【发布时间】:2018-04-23 09:39:44
【问题描述】:

我是 VSC 新手。

我已通过 stackoverflow 进行搜索,但找不到与 g++ 错误相关的问题/解决方案 no such file or directory。我在使用 tasks.json 2.0 版时遇到了这个问题。

如果我在命令行上调用 g++,它会编译并工作。

我的 Subclass.cpp 文件位于此目录中:
“/home/superben/ESP32VSC/CodeExamples/Inheritance/”,也在我的 c_cpp_properties.json 文件中。

我的 c_cpp_properties.json:

{
        "name": "Linux",
        "includePath": [
            "${workspaceFolder}",
            "/home/superben/ESP32VSC/CodeExamples/Inheritance",
            "/usr/include/c++/7",
            "/usr/include/x86_64-linux-gnu/c++/7",
            "/usr/include/c++/7/backward",
            "/usr/lib/llvm-6.0/lib/clang/6.0.1/include",
            "/usr/local/include",
            "/usr/include/x86_64-linux-gnu",
            "/usr/include"
        ],
        "defines": [],
        "intelliSenseMode": "clang-x64",
        "browse": {
            "path": [
                "${workspaceFolder}",
                "/home/superben/ESP32VSC/CodeExamples/Inheritance/",
                "/usr/include/c++/7",
                "/usr/include/x86_64-linux-gnu/c++/7",
                "/usr/include/c++/7/backward",
                "/usr/lib/llvm-6.0/lib/clang/6.0.1/include",
                "/usr/local/include",
                "/usr/include/x86_64-linux-gnu",
                "/usr/include"
            ],
            "limitSymbolsToIncludedHeaders": true,
            "databaseFilename": ""
        },
        "compilerPath": "/usr/bin/clang",
        "cStandard": "c11",
        "cppStandard": "c++17"
    },

我的 tasks.json 文件:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
    {
        "label": "build subClass",
        "type": "shell",
        "command": "g++",
        "args": [
            "Subclass.cpp"
        ],
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
]

}

VSC 构建任务的输出错误:

> Executing task: g++ Subclass.cpp <

g++: error: Subclass.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated.
The terminal process terminated with exit code: 1

我显然在设置 VSC 方面缺少一些简单的东西,以便它可以找到 cpp 文件,但我无法弄清楚它是什么,而且我查看过的问题都没有帮助解决。我没有 Makefile,因为我认为这不是必需的,但也许这就是问题所在......

感谢您的任何见解!

【问题讨论】:

  • 顺便说一句 - 我在 Ubuntu 17.10 上。
  • 另外,我在其他 VSC 项目上没有这个问题,因为它们都使用旧版本的 tasks.json。本例中的版本是 2.0.0,旧版本是 "version": "0.1.0",所以我怀疑是 tasks.json 的问题。

标签: visual-studio-code vscode-settings


【解决方案1】:

我无法做任何可以纠正构建的事情,所以我最终将代码从 ${workspaceFolder}/Inheritance 直接移动到 ${workspaceFolder},而不管“includePath”和“browse”是什么我在 c_cpp_properties.json 中定义的“路径”。我是否使用完全限定的目录结构或派生的 ${workspaceFolder} 目录也无关紧要。

如果代码不在 ${workspaceFolder} 中,而是在该目录下的目录中(例如,${workspaceFolder}/Inhertance,则找不到。

因此,从我有限的知识和努力看来,所有 cpp 代码(没有检查 .h 是否也受到约束)必须放在 ${workspaceFolder} 中,以使“构建任务”正常工作。

我在测试中没有使用 Makefile,只是内置的“构建任务”。

【讨论】:

    猜你喜欢
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 2021-12-13
    • 2017-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多