I'm working on a simple makefile using implicit rules, and not really understanding how make is deciding its execution order. When I have my makefile setup like this, it says it can't find Wave.o:
CXX = g++
AudioSample: Wave.o AudioSample.o
$(CXX) -o AudioSample AudioSample.o Wave.o
AudioSample.o: Wave.h PCADPCM.h
$(CXX) -c AudioSample.cpp
Wave.o: Wave.h
Terminal output:
g++ -o AudioSample AudioSample.o Wave.o
g++: error: Wave.o: No such file or directory
make: *** [AudioSample] Error 1
However when I change the order of the targets it works fine:
AudioSample: Wave.o AudioSample.o
$(CXX) -o AudioSample AudioSample.o Wave.o
Wave.o: Wave.h
AudioSample.o: Wave.h PCADPCM.h
$(CXX) -c AudioSample.cpp
Terminal output:
g++ -c -o Wave.o Wave.cpp
g++ -c AudioSample.cpp
g++ -o AudioSample AudioSample.o Wave.o
Whats the problem??
Double-check for Tabs vs Spaces in your Makefile
.
For example with Vim editor, you can search for tabs /\\t
or add the following to your config:
" in ~/.vimrc
listchars=tab:»»,trail:·,nbsp:~
set list
You clearly have a hidden Tab in the Wave.o
rule (shown like in my editor):
Wave.o : Wave.h
»»»»»»
This tab breaks implicit rules to generate Wave.o
. Remove extra Tabs and it will be fine like your second Makefile
where there is no room for Tab as the target is the very last line of file.
For information, Wave.h
is a prerequisite and is not used by make
to guess the source file name ( Wave.cpp
in this case). Even Wave.o : Wave.cpp
wouldn't have helped.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.