在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
中的包含路径。
我这样做了,它仍然说:“没有这样的文件或目录”。