c - Header.h:没有这样的文件或目录
问题描述
我试图在编译中链接我的 c 文件和头文件,但出现以下错误:
fatal error: header1.h: No such file or directory #include <header1.h>
问题是,我在每个 c 文件中都包含了头文件#include <header1.h>
,并使用命令编译gcc header1.h file1.c file2.c main.c -Wall -std=c99
但仍然在每个 c 文件中给我错误。我已经从下面的每个文件中包含了我的代码的顶部。
header1.h:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct microtreat{
int id;
char user[51];
char text[141];
struct microtreat*next;
}treat;
主.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <header1.h>
文件 1:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <header1.h>
文件 2:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <header1.h>
如何修复此错误?谢谢
解决方案
尝试
#include "header1.h"
当您使用 <> 包含时。预处理器在某些路径中搜索标题,但如果你想在你的 c 文件目录中包含文件,你应该使用 include ""
如果你想在其他目录中包含头文件,你可以使用头文件所在的目录编译它,如下所示:
gcc some_compilation_flags name_of_c_file_to_compile.c -iquote /path/to/the/header/directory
标志 -iquote 告诉编译器包含此目录以在其中找到包含文件
推荐阅读
- html5-canvas - 无法打开使用 canvas.toDataUrl 创建的 PNG
- java - Springdoc 随机 api-docs 生成
- visual-studio-code - VSCode 扩展在哪里存储它们的数据文件?
- python-3.x - Pandas tolist() 函数正在更改默认日期时间格式值
- javascript - 无法防止节点崩溃并在响应中发送错误
- javascript - 在 React 中显示从 input type="file" 中选择的视频的预览
- python - TensorFlow 路径性能安装
- amazon-web-services - AWS CloudEndure 迁移细节
- r - 当给出均值和方差时,R 中的 ANOVA 和 LSD 分组
- c# - Xamarin 表单 - Webview 检测 URL 更改