Question

Everywhere I search I keep seeing this helpful rule

moc_%.cpp: %.h
   $(MOC) $(DEFINES) $(INCLUDES) $< -o $@

It doesn't work. The Makefile goes

MOC:= /path/to/moc

.PHONY clean:
    rm moc_*.cpp

moc: moc_file.cpp

#moc_file.cpp: file.h # this works
#    $(MOC) $< -o $@

moc_%.cpp: %.h
    $(MOC) $< -o $@

The commented line, uncommented, works but the general rule doesn't. It prints out No rule to make target 'moc_file.cpp', needed by 'moc' Can anyone give any insight why it doesn't or what I am doing wrong?

Was it helpful?

Solution

Pattern rules may or may not be used by make depending on the weather or time of day (can you tell I don't like them?). Instead, turn them into static pattern rules by prefixing them with the list of targets you want them to apply to:

moc_file.cpp: moc_%.cpp: %.h
    $(MOC) $< -o $@
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top