0
    #-----------------------------------------------------------------------    ------
# Choose a compiler & its options
#--------------------------------------------------------------------------

CC   = gcc
OPTS = -W -O3

#--------------------------------------------------------------------------
# Add the debug flag to compile for use by a debugger
#--------------------------------------------------------------------------
#DEBUG=-g

#--------------------------------------------------------------------------
# Add the names of the directories
#--------------------------------------------------------------------------
SRCDIR= src
OBJDIR= obj
INCDIR= include
BINDIR= bin

#--------------------------------------------------------------------
# Add the rest of the source files. Don't forget to add the '\' character
# to continue the line. You don't need it after the last source file
#--------------------------------------------------------------------
SRCS=$(SRCDIR)/Lab12.c \ Function1.c \ Function2.c \ Function3.c \                                   Function4.c \          Function5.c 

#--------------------------------------------------------------------
# You don't need to edit the next few lines. They define other flags
# used in the compilation of the source code
#--------------------------------------------------------------------
INCLUDE = $(addprefix -I,$(INCDIR))
OBJS=${SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o}
CFLAGS   = $(OPTS) $(INCLUDE) $(DEBUG)

#--------------------------------------------------------------------
# Add the name of the executable after the $(BINDIR)/
#--------------------------------------------------------------------
TARGET = $(BINDIR)/ Lab12

all: $(TARGET)

$(TARGET): $(OBJS) 
    ${CC} ${CFLAGS} -o $@ $(OBJS)

$(OBJS): $(OBJDIR)/%.o : $(SRCDIR)/%.c
    $(CC) $(CFLAGS) -c $< -o $@

clean:
    rm -f $(OBJS)

 cleanall:
    rm -f $(OBJS)
    rm -f Lab12

 #--------------------------------------------------------------------
 # Add a target named cleanall that will remove the object files as well
 # as the executable
 #--------------------------------------------------------------------

I have all my "header" files in the include folder. I have all my source code in the src folder (Lab12.c , Function1.c, Function2.c ...). I keep getting this error when i use the make command.

Makefile:45: target Function1.c' doesn't match the target pattern Makefile:45: target Function2.c' doesn't match the target pattern Makefile:45: target Function3.c' doesn't match the target pattern Makefile:45: target Function4.c' doesn't match the target pattern Makefile:45: target ` Function5.c' doesn't match the target pattern gcc -W -O3 -Iinclude -c -o Function1.c gcc: no input files make: *** [ Function1.c] Error 1

I cant quite figure out why it is behaving this way. All these files are in the src code folder so why isnt the system recognizing them?

3
  • There seems to be an issue with the formatting in my post. In the original Makefile. Function4.c and Function5.c are present.
    – John Doe
    Commented Nov 28, 2015 at 14:44
  • In oder to paste lines together, the backslash must be the last character on a line; there mustn't be any other character, not even whitespace, between the backslash and the end of the line. You can put various objects on one line, but then you don't have to separate them with backslashes.
    – M Oehm
    Commented Nov 28, 2015 at 14:50
  • 1
    If Function1.c and so on are in $(SRCDIR), you must prepend the directory to these files, too. (Or you don't specify $(SRCDIR) with any of the files and make a pattern substitution later.)
    – M Oehm
    Commented Nov 28, 2015 at 14:51

1 Answer 1

4
SRCS=$(SRCDIR)/Lab12.c \ Function1.c \ Function2.c \ Function3.c \

seems wrong; you should try

SRCS=$(SRCDIR)/Lab12.c Function1.c Function2.c Function3.c

instead

UPDATE

If Function1.c and so on are in ´$(SRCDIR)`, you must prepend the directory to these files, too. (comment from M Oehm)

4
  • Or put them on separated lines, each -except the last one- ending with a backslash Commented Nov 28, 2015 at 14:52
  • I changed the line with the suggestions made in this post. However, I still get the error message. What exactly do you mean by prepend the directory?
    – John Doe
    Commented Nov 28, 2015 at 15:43
  • SRCS=$(SRCDIR)/Lab12.c $(SRCDIR)/Function1.c $(SRCDIR)/Function2.c $(SRCDIR)/Function3.c
    – OznOg
    Commented Nov 28, 2015 at 15:58
  • @JohnDoe : Please accept the answer if it has answered your question. You can accept the answer by clicking the check mark beside OznOg's answer. Thanks, and welcome to StackOverflow!
    – wizurd
    Commented Nov 28, 2015 at 18:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.