Reputation: 8688
Hello:
g++ Hello.cc dep.o -o Hello
dep.o: dep.cc dep.h
g++ -c dep.cc
I am trying out this makefile,but I want the target to be "make Hello". How should I modify my makefile? It work when I typed "make".
Upvotes: 0
Views: 96
Reputation: 477660
You need to add all the dependencies, recursively:
Hello: Hello.cc dep.o
g++ -o $@ $+
dep.o: dep.cc dep.h
g++ -c -o $@ $<
It would probably be better to add a separate compilation stage for Hello.o
, but I'll stick with the format prescribed by the question. You should probably also add $(CXXFLAGS)
and $(LDFLAGS)
to the compilation and link stages, respectively, and replace g++
by $(CXX)
.
Upvotes: 2