Assuming I create a .h
file for the specification of a function
func.h
#ifndef FUNC_H
#define FUNC_H
int xPy(int x, int y);
#endif //FUNC_H
Then I created the implementation of this function in a .c
file, like:
func.c
int xPy(int x, int y) {
int result;
result = x+y;
return result;
}
I can include "func.h"
in a new file (suppose main.c
)
Supposed code for main.c
#include "func.h"
int main() {
int a = func(10, 10);
return 0;
}
So far so good, though, in the build process seems not to be enough to do
gcc main.c -o main
I have to do
gcc func.c main.c -o main
I'd like to know why this is necessary. Should the #include "func.h"
directive not have the compiler fetch the func.c
file automatically?
In case I'm using GCC 8.2.0.