One way to do this is to simply keep all the files discrete (you do not really need an .h file for each .c file), for example:
main.c
Code:
#include <stdio.h>
int main(void) {
int x = test(); /* test() is defined elsewhere */
printf("%d\n",x);
return 0;
}
test.c
Code:
int test() {
return 5;
}
You can now simply go:
gcc main.c test.c
This will produce one executable (a.out, since we didn't give it a name) and everything will work hunky-dory, no need for includes.
My preferred, alternative way if you have a bunch of files is to use one single header file which contains all of the prototypes for all the functions included in any file, and all necessary standard library includes for all files.
main.h
Code:
#include <stdio.h>
/* prototypes */
int test();
Then you include it in the file containing main(), eg.
Code:
#include "main.h"
#include "test.c"
int main(void) {
This is slightly easier to compile:
gcc main.c
but the result is the same.