2017-10-08 62 views
-1
#use g++ for everything 
CC= g++ 

# include debugging symbols in object files, 
# and enable all warnings 
FLAGS= -g -Wall -std=c++11 

BSTHPP= BST.hpp BSTNode.hpp BSTIterator.hpp 

all: main 

bst: testBST.o $(BSTHPP) 
     $(CC) $(FLAGS) -o bst testBST.o $(BSTHPP) 

main: main.o $(BSTHPP) 
     $(CC) $(FLAGS) -o main main.o $(BSTHPP) 

main.o: $(BSTHPP) 
     $(CC) $(FLAGS) -c main.cpp 

testBST.o: testBST.cpp 
     $(CC) $(FLAGS) -c testBST.cpp 

clean: 
     $(RM) main bst *.o 

我更改了BST.hpp文件,然後運行make bst。但我調試了幾次,並找出首先,我需要make clean,然後重新編譯。但爲什麼?任何人都可以向我解釋嗎?Makefile不重新編譯,如果不乾淨

+0

窺視'-MD'選項和'包括* .d' – o11c

回答

1

這是.o文件,需要依賴於.hpp,而不是可執行文件(它也不應該在其配方中提及它們)。

+0

您好,我剛剛更新的Makefile。你認爲這一次,BST.hpp中的改變會使它重新編譯嗎? – Chen

+0

@Chen:不要你的問題編輯的問題。它看起來更接近,但還有幾個額外的$(BSTHPP)。 –

+0

其實,這是有問題的人。那麼爲什麼可執行文件依賴於hpp會使其停止重新編譯? – Chen