0
我用gedit爲我的迷你項目編寫了一個makefile。 當我運行「make」時,創建了所有的* .o和可執行文件。 一旦我改變了我的一個文件(沒有弄乾淨或製作-B) 它顯示它再次編譯被折斷的文件並再次鏈接所有對象。 但可執行文件的工作原理沒有任何改變。 (後「讓-B」的可執行文件運行正常)什麼是製作文件格式
CC = g++
CFLAGS = -Wall
OBJS = pawn.o knight.o bishop.o rook.o queen.o king.o board.o
movement.o game.o
all: ex1
ex1: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o ex1
pawn.o: chess/tools/pawn.cpp chess/tools/tool.hpp
$(CC) $(CFLAGS) -c chess/tools/pawn.cpp
knight.o: chess/tools/knight.cpp chess/tools/tool.hpp
$(CC) $(CFLAGS) -c chess/tools/knight.cpp
bishop.o: chess/tools/bishop.cpp chess/tools/tool.hpp
$(CC) $(CFLAGS) -c chess/tools/bishop.cpp
rook.o: chess/tools/rook.cpp chess/tools/tool.hpp
$(CC) $(CFLAGS) -c chess/tools/rook.cpp
queen.o: chess/tools/queen.cpp chess/tools/tool.hpp
$(CC) $(CFLAGS) -c chess/tools/queen.cpp
king.o: chess/tools/king.cpp chess/tools/tool.hpp
$(CC) $(CFLAGS) -c chess/tools/king.cpp
board.o: chess/board.cpp chess/board.hpp
$(CC) $(CFLAGS) -c chess/board.cpp
movement.o: chess/movement.cpp
$(CC) $(CFLAGS) -c chess/movement.cpp
game.o: chess/game.cpp
$(CC) $(CFLAGS) -c chess/game.cpp
clean:
rm *.o
如果還有其他問題或建議用make文件的設計,我會很高興聽到這個消息。
編輯1)程序不會在屏幕上打印任何內容。 2)的變化是king.cpp文件(位於另一個文件夾)打印打印更改屏幕
[[email protected] chess]$ ls
chess ex1 Makefile
[[email protected] chess]$ ls chess
board.cpp board.hpp game.cpp movement.cpp tools
[[email protected] chess]$ ls chess/tools
bishop.cpp king.cpp knight.cpp pawn.cpp queen.cpp rook.cpp tool.hpp
[[email protected] chess]$ make
g++ -Wall -c chess/tools/pawn.cpp
g++ -Wall -c chess/tools/knight.cpp
g++ -Wall -c chess/tools/bishop.cpp
g++ -Wall -c chess/tools/rook.cpp
g++ -Wall -c chess/tools/queen.cpp
g++ -Wall -c chess/tools/king.cpp
g++ -Wall -c chess/board.cpp
g++ -Wall -c chess/movement.cpp
g++ -Wall -c chess/game.cpp
g++ -Wall pawn.o knight.o bishop.o rook.o queen.o king.o board.o movement.o game.o -o ex1
[[email protected] chess]$ ./ex1
[[email protected] chess]$ *** AT this stage i change the file
[[email protected] chess]$
[[email protected] chess]$ make
g++ -Wall -c chess/tools/king.cpp
g++ -Wall pawn.o knight.o bishop.o rook.o queen.o king.o board.o movement.o game.o -o ex1
[[email protected] chess]$ ./ex1
[[email protected] chess]$
[[email protected] chess]$ make -B
g++ -Wall -c chess/tools/pawn.cpp
g++ -Wall -c chess/tools/knight.cpp
g++ -Wall -c chess/tools/bishop.cpp
g++ -Wall -c chess/tools/rook.cpp
g++ -Wall -c chess/tools/queen.cpp
g++ -Wall -c chess/tools/king.cpp
g++ -Wall -c chess/board.cpp
g++ -Wall -c chess/movement.cpp
g++ -Wall -c chess/game.cpp
g++ -Wall pawn.o knight.o bishop.o rook.o queen.o king.o board.o movement.o game.o -o ex1
[[email protected] chess]$ ./ex1
Print Change
[[email protected] chess]$
只是爲了澄清,如果你改變一個源文件並運行'make'目標文件正在構建,但可執行文件'ex1'沒有被重新鏈接?你是否可以將'make'的輸出複製粘貼到你的問題中,以便我們看到它的輸出?你如何運行你的應用程序?您是否在構建或運行程序之前隨時更改目錄? –
如果缺少'$(CC)'的'-o'標誌,則會在源旁邊創建目標文件。假設你改變了'chess/tools/king.cpp'並且說'make',那麼你會得到一個新的'chess/tools/king.o'。但'ex1'想連接'king.o'而不是'chess/tools/king.o'。這並不能解釋爲什麼'make -B'有幫助,但也許我錯過了什麼? –
在編譯之前是否保存了更改的文件? –