正如我希望你知道,Makefile
由./configure
腳本生成。 您感興趣的所有行都是自動生成的依賴關係。實際上, 它們只是 目錄中文件Makefile.depend
的附加內容,它是分發的一部分,並且是在gcc的幫助 提前生成的。
因此,例如,
./dir_utils.lo: ../include/net-snmp/output_api.h
只是通知說./dir_utils.lo
取決於../include/net-snmp/output_api.h
的極其重要的事實make
。那麼如果./dir_utils.lo
比../include/net-snmp/output_api.h
舊,make
將重新制作 ./dir_utils.lo
只要它有一些配方可以做到這一點,它有。
這裏是一個項目:
的main.c
#include "hw.h"
#include <stdio.h>
int main(void)
{
puts(HW);
return 0;
}
hw.h
#ifndef HW_H
#define HW_H
#define HW "Hello World"
#endif
的Makefile
CC := gcc
.PHONY: all clean
all: hw
hw: main.o
$(CC) -o [email protected] $<
clean:
rm -f hw main.o
生成並運行它:
$ make && ./hw
gcc -c -o main.o main.c
gcc -o hw main.o
Hello World
但是有在Makefile中的錯誤。它不知道main.o
取決於hw.h
:
$ touch hw.h
$ make
make: Nothing to be done for 'all'.
追加一條依賴於生成文件:
main.o: hw.h
,然後重試:
$ make
gcc -c -o main.o main.c
gcc -o hw main.o
錯誤修正。
Makefile中是否有'.c.lo' *後綴規則*?如果是這樣,那麼對於每個目標都不需要明確的配方。 –
是有: '.c.lo:' \t \t'$(libtool的)--mode =編譯$(CC)$(CPPFLAGS)$(CFLAGS)-c -o $ @ $ <' – mfloris