I have the following simple problem in a Makefile:
%.o:: %.c
gcc -o $@ -c $<
lib1.a: test.o
ar -r $@ test.o
rm *.o
lib2.a: test.o
ar -r $@ test.o
rm *.o
all: lib1.a lib2.a
make lib1.a
or make lib2.a
work properly. However, make all
gives:
gcc -o test.o -c test.c
ar -r lib1.a test.o
rm *.o
ar -r lib2.a test.o
ar: test.o: No such file or directory
make: *** [lib2.a] Error 1
I need to do the rm *.o
cause I want the object file to compile each time (in my real Makefile, I have a more complex use case where I compile with different flags).
How can I fix this problem? It seems that make
compiles the object file only once.
I tried with .PHONY
instead of doing the rm
, but again, it compiles only once.