R
R
rust212014-12-22 03:00:10
GNU Make
rust21, 2014-12-22 03:00:10

Creating a simple makefile. Why doesn't the clean target work?

I'm learning the make utility. As an example, I threw the following simple example in the makefile:

.PHONY: all clean

all: hello

clean:
  rm -rf hello *.o

main.o: main.cpp
  g++ -c -o main.o main.cpp

hello: main.o
  g++ -o hello main.o

I can’t understand why clean doesn’t work (the object file main.o appears in the folder).
Tell me what I'm doing wrong?!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
brutal_lobster, 2014-12-22
@rust21

Most likely you do not specify the target explicitly. By default, the first target is executed (except for those that start with a period) - and in this target (all) there is no clean in the dependencies.
www.gnu.org/software/make/manual/make.html#How-Mak...
And .PHONY is used to bypass file name and script match (try removing clean from .phony, create clean file and do make clean)
https://www.gnu.org/software/make/manual/html_node...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question