Reputation: 24705
I have a Makefile with this content
$ cat Makefile
all: locality
locality: src/locality.o
g++ src/locality.o -o locality
locality.o: src/locality.cpp
g++ -O3 -c src/locality.cpp
clean:
rm -rf src/*.o locality
However when I run make
, I see some slightly different output!
$ make clean
rm -rf src/*.o locality
$ make
g++ -c -o src/locality.o src/locality.cpp
g++ src/locality.o -o locality
So where is -O3
??
Upvotes: 0
Views: 46
Reputation: 798676
You tripped over a built-in rule in GNU make, namely %.o: %.c
. Use $CFLAGS
instead.
CFLAGS=-O3
all: locality
locality: src/locality.o
g++ src/locality.o -o locality
clean:
rm -rf src/*.o locality
Upvotes: 2
Reputation: 72649
Make is using an implicit rule to create src/locality.o
because you have no rule for it (you only have a rule for locality.o
in the current directory, not in src
.
This is what you get for violating one of Paul's rules of Makefiles:
Every non-.PHONY rule must update a file with the exact name of its target.
To do that, you should use $@
in your rule to designate the target file.
Upvotes: 1