Makefile clean not removing *.o files?
Solution 1
To check what really happens, run "make clean" and examine the output of that command.
- Is it nothing? Then there might be a file called "clean" in the current directory. Remove it and try again.
- Does it start with "rm ..."? Then it seems to be normal.
- In all other cases, tell us the exact output you get.
To check whether the commands are really run, insert some "echo" commands before and after the "rm" command. Are they executed?
And finally, did you distinguish between tab characters and spaces? In Makefiles the difference is important. Commands must be indented using tabs.
Solution 2
One way that make clean can 'fail' to execute anything is if there is a file called clean in your directory, possibly the result of running make -t clean. This would create a file, so when you next ran make clean, it would appear up to date - it has no dependencies, so there is no reason to run the action.
If you use GNU Make, ensure that you have the line:
.PHONY: clean
That will stop make -t from creating clean and will ensure that the actions are run.
Related videos on Youtube
nacho4d
C/C++/Objective-C/C#/Javascript/shell-script/Japanese/Go/Spanish/English I love this site. So Helpful! https://twitter.com/nacho4d http://nacho4d-nacho4d.blogspot.com/
Updated on December 27, 2020Comments
-
nacho4d almost 2 yearsI wonder why this won't delete/clean *.o files generated when running make?
# UNIX Makefile CXX = g++ LD = g++ CXXFLAGS = -g testlfunction: lfunction.o lfunctionlist.o lprocessor.o testlfunction.o $(LD) -o [email protected] $^ clean: rm *.o testlfunctionbefore it use to be
$(RM) *.o testlfunctionbut it didn't work also ;(
Why is this?
-
Jonathan Leffler almost 12 yearsThe difference betweenrmand$(RM)is likely to be thatRM = rm -fwhich won't fail if one of the listed files is missing, whereas using justrmmeans that if any of the listed files is missing, the clean operation will fail. For example, if you domake clean allbut thecleanfails, theallphase won't be built.
-