Reputation:
I'm trying to link my c files and header files in compilation, but get the following error:
fatal error: header1.h: No such file or directory #include <header1.h>
The problem is, I have included the header file using #include <header1.h>
in each c file, and compiled using the command gcc header1.h file1.c file2.c main.c -Wall -std=c99
But still gives me the error in every c file. I've included the top of my code from each file below.
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;
main.c:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <header1.h>
file 1:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <header1.h>
file 2:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <header1.h>
How do I fix this error? Thanks
Upvotes: 0
Views: 4684
Reputation: 300
try
#include "header1.h"
when you use the <> include. the pre processor search's for the header in certain paths but if you want to include file in the directory of your c files you should use include ""
if you want to include header file in other directory you can compile it with the directory which the header is in like so:
gcc some_compilation_flags name_of_c_file_to_compile.c -iquote /path/to/the/header/directory
the flag -iquote say to the compiler to include this directory to find the include file in it
Upvotes: 1
Reputation: 1247
There are two ways of including headers in C/C++.
#include <header.h>
looks for the header in the system path
#include "header.h"
starts looking from the local folder of the file including the header
Here there is a much more detailed explanation
What is the difference between #include <filename> and #include "filename"?
Upvotes: 0