Reputation: 12311
Lets assume I have a little project with the following make-file. Please attention to the generation of the o-file (2 dependencies - to the .cpp and the .hpp).
LIB_OPTS = -lpthread
CPP_OPTS = -std=c++11 -Wall
all: main
${CXX} ${CPP_OPTS} ${LIB_OPTS} *.o -o main
main: a.o b.o c.o main.o
%.o: %.cpp %.hpp
${CXX} ${CPP_OPTS} ${LIB_OPTS} -g -c $< -o $@
clean:
rm *.o
a, b and c do have cpp and hpp-files.
main does only have a .cpp.
Here is the output.
g++ -std=c++11 -Wall -lpthread -g -c a.cpp -o a.o
g++ -std=c++11 -Wall -lpthread -g -c b.cpp -o b.o
g++ -std=c++11 -Wall -lpthread -g -c c.cpp -o c.o
g++ -c -o main.o main.cpp
g++ -std=c++11 -Wall -lpthread *.o -o main
What about the generation of main.o???
Where does that come from? Thats nothing to do with my rule.
If I have a main.hpp it would catch my rule. Sure I can create a separate rule for main.o but I expected %.o to make it.
Thanks for help! Chris
Upvotes: 0
Views: 32
Reputation: 100781
GNU make has a number of built-in rules. Among them is a rule that knows how to create a .o
file from a .cpp
file. Since none of your rules are able to create main.o
, make looks through its own built-in rules and finds one that it can use.
You can see a complete list of built-in rules using a command such as:
make -pf/dev/null
You can run make so that it doesn't use any of its own built-in rules with make -r
.
Upvotes: 2