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".
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)
.
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.