加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

makefile – 为什么GNU make delete一个文件

发布时间:2020-12-16 05:53:19 所属栏目:百科 来源:网络整理
导读:我有一个稍微hackish makefile运行测试: ### Run the teststests := tests/test1 tests/test2 ...test: $(tests)$(tests): %: %.c gcc -o $@ $(testflags) $ $@ 它的作品,但它使得做一些我以前从未见过的事情.我的测试目前被打破,导致总线错误. Make给出以
我有一个稍微hackish makefile运行测试:
### Run the tests

tests := tests/test1 tests/test2 ...

test: $(tests)

$(tests): %: %.c
    gcc -o $@ $(testflags) $<
    $@

它的作品,但它使得做一些我以前从未见过的事情.我的测试目前被打破,导致总线错误. Make给出以下输出:

gcc -o tests/test1 [flags blah blah] tests/test1.c
tests/test1
make: *** [tests/test1] Bus error
make: *** Deleting file `tests/test1'

我很好奇最后一行.我从来没有见过Make为什么Make删除编译测试?

注意:我非常重视这个例子,使之更简单.我可能会出现一些错误.

解决方法

因为目标可能未正确构建.下次进行项目时,将尝试重建目标.如果文件没有被删除,make将无法知道出错. make不知道失败是从测试而不是构建目标的过程.

这种行为是否适合您的情况取决于测试的性质.如果您打算修复测试,这样就不会导致总线错误,那么删除目标并不是什么大不了的事情.如果以后要使用目标进行调试,则需要对make进行更改.

不删除目标的一种方法是使用.PRECIOUS目标.

另一个可能是:

$(tests): %: %.c
    gcc -o $@ $(testflags) $<
    -$@

未测试,但documentation表示目标不会被删除:

When an error happens that make has not been told to ignore,it implies that the current target cannot be correctly remade,and neither can any other that depends on it either directly or indirectly. No further commands will be executed for these targets,since their preconditions have not been achieved.

和:

Usually when a command fails,if it has changed the target file at all,the file is corrupted and cannot be used—or at least it is not completely updated. Yet the file’s time stamp says that it is now up to date,so the next time make runs,it will not try to update that file. The situation is just the same as when the command is killed by a signal; see Interrupts. So generally the right thing to do is to delete the target file if the command fails after beginning to change the file. make will do this if .DELETE_ON_ERROR appears as a target. This is almost always what you want make to do,but it is not historical practice; so for compatibility,you must explicitly request it.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读