Makefile:
all: a.out
a.out: b.o a.o
gcc -o b.o a.o
a.o: a.c
gcc -c a.c
b.o: b.c
gcc -c b.c
.PHONY:clean
clean:
rm *.o a.out
with make
, give information:
error: undefined reference to 'main'
collect2: ld return 1
make: * [a.out] error 1
But when put source file a.c
and b.c
into Eclipse CDT, it compiles well.
Please explain what is wrong with my makefile
?
PS: a.c:
int global_1 = 100;
b.c:
extern int global_1;
int main()
{
int global_2 = global_1 * 2;
return 0;
}