如何避免“没有这样的文件或目录"? Make make Makefile目标错误 [英] How to avoid "No such file or directory" Error for `make clean` Makefile target

查看:170
本文介绍了如何避免“没有这样的文件或目录"? Make make Makefile目标错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Makefile,它定义了一个.PHONY干净目标来清理.o文件和可执行文件,该目标看起来像:

I have a Makefile that defines a .PHONY clean target for cleaning up .o files and executables, that target looks like:

...
.PHONY : clean
clean:
    rm $(addprefix $(vq_DIR),$(vq_OBJS)) \
       $(addprefix $(vq_DIR),vq) \
       $(addprefix $(covq_DIR),$(covq_OBJS)) \
       $(addprefix $(covq_DIR),covq) \
       $(addprefix $(covq_2_DIR),$(covq_2_OBJS)) \
       $(addprefix $(covq_2_DIR),covq_2) \
       $(addprefix $(covq_2_DIR),$(test_OBJS)) \
       $(addprefix $(covq_2_DIR),test)

一切正常,但是当其中一些文件不存在时,rm引发错误(没有此类文件或目录),并且输出显示Makefile目标失败,这显然是我想要的

Everything works as it should, but when some of these files do not exist, rm raises an Error (No such file or directory), and the output says that the Makefile target failed, when it clearly did what I wanted.

是否有一种很好的方法可以基本告诉rm命令删除这些文件(如果存在),并且不要抱怨,如果它们不存在"?我在rm的联机帮助页中查找,但没有找到这样的标志.

Is there a good way to basically tell the rm command to "remove these files if they exist, and don't complain if they don't"? I looked up the manpage for rm, and found no such flag.

实际上,我没有注意到联机帮助页中-f标志的描述,这是解决方案.

I actually didn't notice the description of the -f flag in the manpage, this is the solution.

推荐答案

使用rm -f(甚至更好的$(RM),由内置make规则提供,可以使用make -p找到) clean规则中的rm.

Use rm -f (or even better $(RM), provided by built-in make rules, which can be found out using make -p) instead of rm in your cleanrule.

这篇关于如何避免“没有这样的文件或目录"? Make make Makefile目标错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆