How to avoid "No such file or directory" Error for `make clean` Makefile target
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 clean
rule.
When Targets Fail
When a target is executed, it returns a status based on whether or not it was successful--if a target fails, then make will not execute any targets that depend on it. For instance, in the above example, if "clean" fails, then rebuild will not execute the "build" target. Unfortunately, this might happen if there is no core file to remove. Fortunately, this problem can be solved easily enough by including a minus sign in front of the command whose status should be ignored:
clean: -rm -f *.o core
~ http://www.cprogramming.com/tutorial/makefiles.html
rm -f
will FORCE and not output any error