gpt4 book ai didi

c - 包含来自另一个目录的头文件

转载 作者:太空狗 更新时间:2023-10-29 16:20:37 25 4
gpt4 key购买 nike

我有一个主目录 A 和两个子目录 BC

目录B包含头文件structures.c:

#ifndef __STRUCTURES_H
#define __STRUCTURES_H
typedef struct __stud_ent__
{
char name[20];
int roll_num;
}stud;
#endif

目录C 包含main.c 代码:

#include<stdio.h>
#include<stdlib.h>
#include <structures.h>
int main()
{
stud *value;
value = malloc(sizeof(stud));
free (value);
printf("working \n");
return 0;
}

但是我得到一个错误:

main.c:3:24: error: structures.h: No such file or directory
main.c: In function ‘main’:
main.c:6: error: ‘stud’ undeclared (first use in this function)
main.c:6: error: (Each undeclared identifier is reported only once
main.c:6: error: for each function it appears in.)
main.c:6: error: ‘value’ undeclared (first use in this function)

structures.h 文件包含到main.c 中的正确方法是什么?

最佳答案

当引用头文件时相对于你的c文件你应该使用#include "path/to/header.h"

表格#include <someheader.h>仅用于内部 header 或明确添加的目录(在带有 -I 选项的 gcc 中)。

关于c - 包含来自另一个目录的头文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7581408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com