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()
.
gcc -o program file2.c file1.c
, change this togcc -o program file1.c file2.c
. Order is important.-lnameoflib
) should be specified after the sources using symbols from them, and if there are inter-lib dependencies, then order of libs matters too, or the grouping options must be used (linker then goes in a loop for the group, until all references are satisfied or no more can be resolved.)