【问题标题】:checking if a.out exists then remove with make clean otherwise do try to remove -- Makefile检查 a.out 是否存在,然后使用 make clean 删除,否则尝试删除 - Makefile
【发布时间】:2021-12-15 01:53:48
【问题描述】:

我有这个简单的makefile,在运行make 命令后,我得到输出parser,我像#: ./parser 一样运行,但有时它也会生成a.out 所以当make 不生成最后一个@987654325 的a.out 时@ 命令然后运行 ​​make clean 会发出警告 rm: can not remove a.out, No such file or directory

所以我喜欢我的make clean 命令,同时检查a.out 是否存在然后删除,否则不要尝试删除。我怎么能在clean: ....里面的makefile中做到这一点

parser: header.h parser.c
    gcc header.h parser.c -o parser
    
clean:
    rm parser a.out 

【问题讨论】:

  • rm -f 忽略丢失的文件
  • 除了警告还有什么具体原因吗?您可以使用rm -f 删除该警告。
  • 精确到其他帖子:只需将 'rm parser a.out' 行替换为 'rm -f parser a.out'

标签: linux makefile sh


【解决方案1】:

通常的做法是强行删除:

clean:
    rm -f parser a.out 

来自rm手册页:

-f, --force
忽略不存在的文件和参数,从不提示

【讨论】:

  • 您还可以告诉我可以删除parser.cheader.h 并且只对.c.h 文件使用隐式规则。你可以请你可以吗。
猜你喜欢
  • 1970-01-01
  • 2016-02-10
  • 2017-10-01
  • 2011-09-17
  • 1970-01-01
  • 2011-03-10
  • 2011-07-30
  • 2011-07-20
  • 1970-01-01
相关资源
最近更新 更多