vscode tasks.json 2.0 g ++没有这样的文件或目录

时间:2018-04-22 18:08:08

标签: visual-studio-code vscode-settings

我是VSC的新手。

我搜索了stackoverflow,但找不到与g ++错误有关的问题/解决方案没有这样的文件或目录。我在使用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,因为我不认为这是必需的,但也许这就是问题....

感谢您的任何见解!

1 个答案:

答案 0 :(得分:0)

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

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

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

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

相关问题