1
votes

I am trying to make a Makefile and I am getting errors:

make: * No rule to make target main.c, needed by main.o. Stop.

Can anyone explain why I am getting this error, or even suggest a fix if possible, Thank you.

TARGET =    example

SRC_FILES = \
Makefile \
README \
a.c \
a.h \
b.c \
b.h \
main.c

OBJS = \
  main.o \
  a.o \
  b.o


CC = gcc
CFLAGS = -g -Wall -std=c99


(TARGET):       $(OBJS)
        $(CC) $(OBJS) $(LDFLAGS) -o $@


$(TARGET):      $(TARGET).html $(TARGET).pdf 

$(TARGET).html:     $(TARGET).umt
        $(UMT) $< >$@

$(TARGET).pdf:      $(TARGET).html
        $(HTML2PS) -N 0 -n $(TARGET).html > $(TARGET).ps
        $(PS2PDF) $(TARGET).ps 
        rm -f $(TARGET).ps


clean:
        rm -f $(TARGET).html $(TARGET).pdf


a.o:        a.c a.h
b.o:        b.c b.h
main.o:     main.c a.h b.h
1
You get this error because there is no main.c in your source directory, nor any other file make knows how to convert to main.o. Should there be one? ATM your makefile expects being able to make the objects main.o, a.o and b.o.Deduplicator
if this is an old-line unix OS you're using, recall that for some OSs, elements of targets have to be indented with real TAB chars, not spaces. I think the error msgs would be different, but worth dbl-chking. Good luck.shellter

1 Answers

0
votes

Deduplicator already explained why you are getting this error. Suggested fix: Provide a main.c, or change the file names in the make file to the names of the files you have (example.c maybe).