Makefile doesn't clean * .o files?

I wonder why this will not delete / clean * .o files created when make is launched?

# UNIX Makefile CXX = g++ LD = g++ CXXFLAGS = -g testlfunction: lfunction.o lfunctionlist.o lprocessor.o testlfunction.o $(LD) -o $@ $^ clean: rm *.o testlfunction 

before it will be used

 $(RM) *.o testlfunction 

but it also did not work (

Why is this?

+4
source share
2 answers

To check what actually happens, run "make clean" and view the output of this command.

  • It's nothing? Then in the current directory there may be a file called "clean". Please remove it and try again.
  • Will it start with "rm ..."? Then it seems normal.
  • In all other cases, tell us the exact result that you get.

To verify that the commands are actually running, insert some echo commands before and after the rm command. Are they being implemented?

And finally, did you distinguish between tabs and spaces? In makefiles, the difference is important. Commands must be indented using tabs.

+4
source

One way that make clean might crash can do something is if there is a file called clean in your directory, possibly the result of running make -t clean . This will create the file, so the next time you run make clean it will appear in the current state - it has no dependencies, so there is no reason to run the action.

If you are using GNU Make, make sure you have the line:

 .PHONY: clean 

This will stop make -t from creating clean and ensure that actions are completed.

+6
source

Source: https://habr.com/ru/post/1333419/


All Articles