了解Makefiles

时间:2012-07-11 00:21:45

标签: makefile

我有以下make文件:

CC = gcc
CCDEPMODE = depmode=gcc3
CFLAGS = -g -O2 -W -Wall -Wno-unused -Wno-multichar
COMPONENTHEADER = Q_OBJECT 
CPP = gcc -E
CPPFLAGS = -I/usr/include/Inventor/annex -D_REENTRANT -I/usr/share/qt3/include  
CXX = g++
CXXCPP = g++ -E
CXXDEPMODE = depmode=gcc3
CXXFLAGS = -g -O2 -fno-exceptions -W -Wall -Wno-unused -Wno-multichar -Woverloaded-    virtual
CYGPATH_W = echo
GUI = QT
Gui = Qt
INCLUDES = 
LIBS = -lSoQt -lqt-mt -lXmu -lXi -lCoin -lGL -lXext -lSM -lICE -lX11 -ldl -lpthread -lm -lcxcore -lcv -lhighgui -lcvaux 
OBJS = MathTools.o PointCloud.o ExtractFeatures.o Tile.o Shape.o RoadDynamic.o
SRCS = MathTools.cpp PointCloud.cpp ExtractFeatures.cpp Tile.cpp Shape.cpp RoadDynamic.cpp main.cpp 
HDRS =  constants.h Shape.h MathTools.h PointCloud.h ExtractFeatures.h Tile.h RoadDynamic.h
WIDGET = QWidget *

all: main


main: main.o ${OBJS}
    ${CC} ${CFLAGS} ${INCLUDES} -o $@ main.o ${OBJS} ${LIBS}

.c.o:
    ${CC} ${CFLAGS} ${INCLUDES} -c $<

depend: 
    makedepend ${SRCS}

clean:
    rm *.o core *~

tar:
    tar cf code.tar  Makefile *.c *.h testfile1

print:
    more Makefile $(HDRS) $(SRCS) | enscript -2r -p listing.ps

我想知道为什么当我运行时输出是

g++ -g -O2 -fno-exceptions -W -Wall -Wno-unused -Wno-multichar -Woverloaded-virtual -I/usr/include/Inventor/annex -D_REENTRANT -I/usr/share/qt4/include    -c -o main.o main.cpp

而不是:

gcc -g -O2 -W -Wall -Wno-unused -Wno-multichar ...

似乎cxx变量覆盖了cc变量。那是为什么?

在这种情况下,“include =”也会做什么?它似乎没有任何设置。

谢谢

1 个答案:

答案 0 :(得分:2)

因为您的目标文件显然是从.cpp文件构建的。您没有明确的规则来构建.cpp文件中的.o文件,因此Make使用implicit rule $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c