开发者

Makefile clean not removing *.o files?

开发者 https://www.devze.com 2023-02-01 20:01 出处:网络
I wonder why this won\'t delete/clean *.o files generated when running make? # UNIX Makefile CXX = g++ LD= g++

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
开发者_Python百科

but it didn't work also ;(

Why is this?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号