Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

理解 make「Nothing to be done for 'all'」訊息

編輯:Linux 教學

訊息含義

執行 make 時出現:

make: Nothing to be done for 'all'.

這不是錯誤,而是表示:

  • 目標檔案已存在且是最新的。
  • 原始碼檔案自上次編譯後未修改(時間戳記未變更)。
  • Makefile 中的依賴關係判斷無需重新建構。

範例說明

假設專案結構:

b/
├── main.c
├── main.o
├── Makefile
├── temp1/
│   ├── Makefile
│   └── temp1.c
└── temp2/
    ├── printhello21.c
    ├── printhello22.c
    └── Makefile

頂層 Makefile 可能包含:

all: b

b: main.o temp1/temp1.o temp2/temp2.o
	gcc -o b main.o temp1/temp1.o temp2/temp2.o

main.o: main.c
	gcc -c main.c

temp1/temp1.o:
	$(MAKE) -C temp1

temp2/temp2.o:
	$(MAKE) -C temp2

首次執行 make 會編譯所有子目錄並產生 b。再次執行無任何檔案異動時,輸出:

[root@localhost b]# make
for i in temp1 temp2; do make -C $i; done
make[1]: Entering directory `/home/b/temp1'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory `/home/b/temp1'
make[1]: Entering directory `/home/b/temp2'
make[1]: Nothing to be done for 'all'.
make[1]: Leaving directory `/home/b/temp2'
gcc -o b main.o temp1/temp1.o temp2/temp2.o
[root@localhost b]# ./b
hello_11
hello_12
hello_21
hello_22

強制重新編譯

  • make clean 清除中間檔(需 Makefile 定義 clean 目標)。
  • touch *.c 更新原始碼時間戳記。
  • make -B 或 make --always-make 強制重建所有目標。

常見誤區

  1. 以為編譯失敗:實際上是成功且無需動作。
  2. 修改了標頭檔 (.h) 但 Makefile 未正確宣告依賴:需使用 gcc -MMD 自動產生 .d 依賴檔並 include 進 Makefile。
Copyright © Windows教程網 All Rights Reserved