Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在VSCode中构建程序时,如何指定包含路径? 假设这是我的项目。_C_Visual Studio Code_Compiler Errors_Vscode Settings_Vscode Tasks - Fatal编程技术网

在VSCode中构建程序时,如何指定包含路径? 假设这是我的项目。

在VSCode中构建程序时,如何指定包含路径? 假设这是我的项目。,c,visual-studio-code,compiler-errors,vscode-settings,vscode-tasks,C,Visual Studio Code,Compiler Errors,Vscode Settings,Vscode Tasks,文件结构: project_root |-- inc | |-- header.h |-- src | |-- helpers.c | |-- main.c header.h #ifndef HEADER_H # define HEADER_H void func(void); #endif helpers.c void func() { /* do something */ } main.c #include "header.h" int ma

文件结构:

project_root
|-- inc
|   |-- header.h
|-- src
|   |-- helpers.c
|   |-- main.c
header.h

#ifndef HEADER_H
# define HEADER_H

void    func(void);

#endif
helpers.c

void    func()
{
    /* do something */
}
main.c

#include "header.h"

int    main(void)
{
    func();
    return (0);
}
c\u cpp\u properties.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/inc",
            ],
            "defines": [],
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "-Wall",
                "-Werror",
                "-Wextra",
                "-o0"
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "group": {
            "kind": "build",
            "isDefault": true
            },
        }
    ],
    "version": "2.0.0"
}
tasks.json

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "${workspaceFolder}/inc",
            ],
            "defines": [],
            "macFrameworkPath": [
                "/System/Library/Frameworks",
                "/Library/Frameworks"
            ],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "-Wall",
                "-Werror",
                "-Wextra",
                "-o0"
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}",
            ],
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "group": {
            "kind": "build",
            "isDefault": true
            },
        }
    ],
    "version": "2.0.0"
}
问题 在VSCode中构建程序时,出现以下错误。
project\u root/src/main.c:xx:xx:致命错误:未找到header.h文件

问题: 如何避免此错误?
(如何让VSCode的构建功能知道我的头在哪里?)

我已经做了什么 我在
c\u cpp\u properties.json
中配置了include路径,因此我没有在
main.c
中获得包含标题的曲线

对我来说,什么不是解决办法 我不想在
main.c
中写入
#include“./inc/header.h”
,所以这对我来说不是一个解决方案

args
属性下,使用
-I
标志指定
tasks.json
中的包含路径。
我这样做了,它仍然说:“没有这样的文件或目录”。