首页 > 解决方案 > 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>

如何修复此错误?谢谢

标签: c

解决方案


尝试

#include "header1.h"

当您使用 <> 包含时。预处理器在某些路径中搜索标题,但如果你想在你的 c 文件目录中包含文件,你应该使用 include ""

如果你想在其他目录中包含头文件,你可以使用头文件所在的目录编译它,如下所示:

gcc some_compilation_flags name_of_c_file_to_compile.c -iquote /path/to/the/header/directory

标志 -iquote 告诉编译器包含此目录以在其中找到包含文件


推荐阅读