[英]How to create target for makefile
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". 我正在尝试这个makefile,但我希望目标是“make Hello”。 How should I modify my makefile? 我该如何修改我的makefile? It work when I typed "make". 当我键入“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. 为Hello.o
添加一个单独的编译阶段可能会更好,但我会坚持使用问题规定的格式。 You should probably also add $(CXXFLAGS)
and $(LDFLAGS)
to the compilation and link stages, respectively, and replace g++
by $(CXX)
. 您也应该分别在编译和链接阶段添加$(CXXFLAGS)
和$(LDFLAGS)
,并用$(CXX)
替换g++
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.