I am having some trouble compiling a few files using headers. Here is a breakdown of my code:
file1.c
#include "header.h"
int main() {
func1();
return 0;
}
file2.c
#include "header.h"
void func1() {
... function implementation ...
}
header.h
void func1();
The error I am getting is:
In function
'main'
:
undefined reference to'func1'
Note: I am just using a simple breakdown of how my 3 files are set up. I need to get this to work with the 3 files. I am setting/including everything properly? I need to use this set up, but I am just unsure how file.c gets reference to the actually implementation of func1()
.
If the error is an undefined reference to func1()
, and there is no other error, then I would think it's because you have two files called header.h
in your project and the other copy is being included instead of your copy with the declaration of func1()
.
I would check the include paths for your project and make sure that the header.h
with your declaration of func1()
is being included first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With