The following example snippet is from "Managing Projects with GNU Make(3rd edition)" p.21.
count_words: counter.o lexer.o -lfl
The author says that make will automatically add count_words.o to prerequisite list by implicit rule. Quoted:
..., make identifies four prerequisites: count_words.o (this prerequisite is missing from the makefile, but is provided by the implicit rule), counter.o, lexer.o, and -lfl.
However, my test doesn't conform to that. Here is my test:
prog: abc.o
@echo $^
abc.o:
@echo abc.o built.
prog.o:
@echo prog.o bulit.
The output after running make is:
abc.o built.
abc.o
make didn't seek for prog.o for the target prog.
What's the problem? Is there something wrong with my test?
By the way, my test is on Cygwin with GNU Make 4.1.
You gave a recipe for your prog target. The author didn't for the count_words target. That's the difference.
The author was counting on the built in %: %.o rule to take effect. You overrode that with your rule.
Remove the @echo $^ from the prog recipe and try again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With