I have 2 .c
files and respective .h
files and main.c
.
The files' content are as follow:
main.c
#include "a.h"
int main() {
a_func();
}
a.h
#include "b.h"
/* struct defined in b.h is used here */
void a_func();
a.c
#include "a.h"
#include "b.h"
void a_func(){...} /* b_func is called within a_func */
b.h
void b_func();
b.c
#include "b.h"
b_func(){...}
I wrote a Makefile to compile main.c
:
main: main.o a.o
gcc main.o a.o -o main
main.o main.c
gcc -c main.c
a.o: a.c a.h b.h
gcc -c a.c
However, make complains:
a.o: In function `a_func':
a.c: undefined reference to `b_func'
I was wondering how should I revise the Makefile to make it work.