用C/C++在Linux上编程时,如果修改了一个头文件,怎样让整个工程自动识别更新呢?那就是使用Makefile自动生成依赖关系。
CC &#61; g&#43;&#43;SHARED &#61; -sharedLIBRARY &#61; library.soINCLUDE &#61;CPPFLAGS &#61;SOURCES &#61; $(wildcard *.cpp)SOURCES &#43;&#61; ../mean.cppOBJECTS&#61;$(SOURCES:.cpp&#61;.o)all:$(LIBRARY)%.d: %.cpp&#64;set -e; rm -f $&#64;;$(CC) $(INCLUDE) -MM $(CPPFLAGS) $<| sed -e &#39;s,.*/.o[ :]*,$*.o : ,g&#39; > $&#64;;sinclude $(SOURCES:.cpp&#61;.d)%.o: %.cpp$(CC) $(INCLUDE) -c $<-o $&#64;$(LIBRARY) : $(OBJECTS)&#64;echo&#64;echo creating library ...&#64;echo$(CC) $(INCLUDE) $(SHARED) -o $(LIBRARY) $(OBJECTS).PHONY: cleanclean:rm -f core *.o *.d $(LIBRARY)