0

so I made a makefile for a c program. For some reason my 'clean' is not working. Here's a little bit of my makefile:

CC=gcc
FLAGS=-c -Wall -I.
CLEANC=rm -rf *.o

move.o: move.c
     $(CC) $(FLAGS) move.c
/*Lot more codes like this^^^*/

clean:
    $(CLEANC)

When I run 'make clean' in command prompt, I'm shown the following:

rm -rf *.o
process_begin: CreateProcess(NULL, rm -rf *.o, ...) failed.
make (e=2): The system cannot find the file specified.
makefile:116: recipe for target 'clean' failed
make: *** [clean] Error 2

I can't figure out what I'm doing wrong. I've tried changing CLEANC to

rm -f *.o
rm *.o 
rm *o
rm -f *.o test.exe //test.exe is executable

but it still gave me the same error no matter what I tried. I could really use the help. Thanks in advance.

ioaop
  • 35
  • 1
  • 1
  • 6
  • Cannot reproduce this. Your Makefile works perfectly with GNU Make 3.81 and GNU Make 4.2.1. – Renaud Pacalet Dec 10 '17 at 07:20
  • What OS? What happens when you try `rm -f *.o` on the command line? – Beta Dec 11 '17 at 03:14
  • It's giving me the same error. I am using Windows 10 with MinGW and MSYS installed. 'make' and 'make compile' works perfectly but for some reason 'make clean' always gives me that same error. – ioaop Dec 11 '17 at 20:12

2 Answers2

9

Judging from the CreateProcess appearing in your error output I assume you are running make under Windows.

This means that there is no rm command, you should use del instead and -rf flags should also be adjusted accordingly.

igagis
  • 1,959
  • 1
  • 17
  • 27
0
OBJS   = $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(notdir $(SRCS))))
DELOBJS = $(addprefix .\obj\,$(patsubst %.c,%.o,$(notdir $(SRCS))))

.PHONY: clean
clean:
    del xxx 
    del $(DELOBJS)

del does not work because Windows uses \ to distinguish file paths,so you have to take OBJS with \path, that is, DELOBJS I wrote

Doj
  • 1,244
  • 6
  • 13
  • 19