虽然Make工作正常,但默认情况下它只编译那些已更改的文件,即使我运行make all
。它说像Nothing to Do
。
我需要编译所有文件的一个场景是当我在多个.c
文件中访问的头文件中更改某些内容时。但是,在我再次打开.c
个save & quit
文件之前,make无法识别它。
Makefile内容可以在这篇文章中看到:
Questions about Makefile - what is "$+" & where are .c files/dependencies called here ?
虽然这也是一个问题,但我想在这里讨论的实际问题是不同的。
为了编译所有文件,我所做的是我运行了make clean
,它确实删除了所有目标文件,然后我再次运行make
,但这次它给出了一个错误: -
....
mec/gen_crc32table > mec/crc32table.h
mec/gen_crc32table: 1: mec/gen_crc32table: Syntax error: end of file unexpected
(expecting ")")
make: *** [mec/crc32table.h] Error 2
我检查了crc32table.h
的内容,但文件为空。因此,我从以前代码的备份中复制crc32table.h
,现在它已成功运行。现在我再次运行make clean
和'make'来检查它,但这次它运行正常。
我不知道这里有什么神秘之处?
我猜这些线路正在做一些我无法理解的事情?请帮帮我。
crc32.o: mec/crc32table.h mec/crc32.c
$(CC) -o $@ -c -I. $(CFLAGS) mec/crc32.c
mec/crc32table.h: mec/gen_crc32table
mec/gen_crc32table > mec/crc32table.h
答案 0 :(得分:1)
问题是这个片段:
mec/crc32table.h: mec/gen_crc32table
mec/gen_crc32table > mec/crc32table.h
问问自己“如果gen_crc32table
命令退出并出错,会发生什么?”停止(好)但留下腐败的crc32table.h
(坏)。两种选择:(i)重写gen_crc32table
,使其接受-o
参数; (ii)shell trickery。
(ⅰ)
mec/crc32table.h: mec/gen_crc32table
mec/gen_crc32table -o mec/crc32table.h
(ⅱ)
mec/crc32table.h: mec/gen_crc32table
mec/gen_crc32table >temp-file-with-an-obscure-name
mv temp-file-with-an-obscure-name $@
如果mv
错误,则gen_crc32table
不会发生。