我正在学习如何使用g ++编写Makefile
。我使用以下example 的代码项目是here。这是在Makefileg ++中的MakeFile。可忽略的命令
# Makefile for Writing Make Files Example
# *****************************************************
# Variables to control Makefile operation
CXX = g++
CXXFLAGS = -Wall -g
# ****************************************************
# Targets needed to bring the executable up to date
main: main.o Point.o Rectangle.o # ***Statement : 1
$(CXX) $(CXXFLAGS) -o main main.o Point.o Rectangle.o #Commands underneath dependencies have tabs before them
# The main.o target can be written more simply
main.o: Point.h Rectangle.h # ***Statement : 2
$(CXX) $(CXXFLAGS) -c main.cpp
Point.o: Point.h # ***Statement : 3
Rectangle.o: Rectangle.h Point.h # ***Statement : 4
现在我对此我也参考使用,便于质疑的声明关键字的具体线的一些问题。
1-我理解的语句是否正确。当g ++在main之后遇到main.o(它是目标main.o的依赖)时:它跳转到目标main.0(语句2)。然后,它检查main.o的依赖关系(如果依赖项(找到这两个头文件),它会运行该命令),然后返回以完成其对下一个依赖项的任务,如此等等。
2-对于Point.o的依赖性是Point.h为什么没有命令作为这样
$(CXX) $(CXXFLAGS) -c Point.cpp
同样地,对于Rectangle.o为什么是有它的依赖性这样
没有命令$(CXX)$(CXXFLAGS)-c Rectangle.cpp
如果有人能澄清这一点,我将不胜感激。
你缺少'xxx.cpp'为'xxx.o' ... – PiotrNycz 2014-10-20 06:21:38
@PiotrNycz我的GNU使(3.81)implicitl的版本依赖y增加了依赖性。 – juanchopanza 2014-10-20 06:33:32