Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile clean not removing *.o files?

Tags:

makefile

I 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 $@ $^

clean:
    rm *.o testlfunction

before it use to be

$(RM) *.o testlfunction

but it didn't work also ;(

Why is this?

like image 574
nacho4d Avatar asked Dec 26 '10 22:12

nacho4d


People also ask

How do I clean my makefile?

The Cleanup Rule clean: rm *.o prog3 This is an optional rule. It allows you to type 'make clean' at the command line to get rid of your object and executable files. Sometimes the compiler will link or compile files incorrectly and the only way to get a fresh start is to remove all the object and executable files.

Can I delete O files?

If you want to remove the objects after compile, you can add the rm command after the $(CC). This ensures that after the compilation is done all the .o files and the *~ files are removed.

What is make clean in terminal?

The make clean is a command that removes all executable files from a program binary and coding directory. That means it removes all the object files that were created in the meantime.

What is makefile target?

A simple makefile consists of “rules” with the following shape: target … : prerequisites … recipe … … A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ' clean ' (see Phony Targets).


1 Answers

To check what really happens, run "make clean" and examine the output of that command.

  1. Is it nothing? Then there might be a file called "clean" in the current directory. Remove it and try again.
  2. Does it start with "rm ..."? Then it seems to be normal.
  3. 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.

like image 189
Roland Illig Avatar answered Sep 29 '22 12:09

Roland Illig