Makefile

Solved
Hello everyone, I created a Makefile and I have several problems...

When I try to place an @echo I get the message

Makefile:16: *** missing separator (did you mean TAB instead of 8 spaces?). Stopped.

or even for clean I get the message:

make: *** No rule to make target « rm », needed for « clean ». Stopped.

here is my code:

OBJS = main.o command.o
LINKOBJET = main.o command.o
BIN = ircweb
CC = gcc
CFLAGS = -W -Wall -ansi -pedantic -D_REENTRANT -std=c99
LDFLAGS = -I /usr/include/mysql/ -L /usr/lib/mysql/ -lmysqlclient -lpthread
RM = rm -f

all: $(BIN) clean

clean: ${RM} $(OBJS) *.c~

$(BIN): $(OBJS)
$(CC) $(LINKOBJET) -o $(BIN) $(LDFLAGS)

main.o: main.c
$(CC): $(CFLAGS) -c main.c -o main.o

command.o: command.c
$(CC): $(CFLAGS) -c command.c -o command.c
@echo end of compilation.

Can you help me?
Configuration: Linux Debian Mozilla 1.8.1.10

9 answers

  • Votes
  • Date
  • Descending date
  1. Thank you, but I had already read that tutorial, and it doesn't really help me, sorry...

    Could you show me how to do it on my Makefile? That would really help me understand.
    1. Moderator
      Well, I don't know, in your case it would look more like this:
      OBJS = main.o command.o LINKOBJET = main.o command.o BIN = ircweb CC = gcc CFLAGS =-W -Wall -ansi -pedantic -D_REENTRANT -std=c99 LDFLAGS=-I /usr/include/mysql/ -L /usr/lib/mysql/ -lmysqlclient -lpthread RM = rm -f all: $(BIN) clean clean: ${RM} $(OBJS) *.c~ $(BIN): $(OBJS) $(CC) $(LINKOBJET) -o $(BIN) $(LDFLAGS) main.o: main.c $(CC) $(CFLAGS) -c main.c -o main.o command.o: command.c $(CC): $(CFLAGS) -c command.c -o command.c @echo end of compilation. 

      (or each line is a tab)

      Good luck.
      1. What has changed between my code and the one you gave me?
        1. I tried the code and now I have: *** missing separator. Stopped.
          1. Moderator
            <5> Line breaks and tabs
            <6> Did you use tabs correctly:
            clean: <TAB>${RM} $(OBJS) *.c~ $(BIN): $(OBJS) <TAB>$(CC) $(LINKOBJET) -o $(BIN) $(LDFLAGS) ...
            1. I just understood with your last post, actually you have to use the tab key. Because now it works without any problems, thanks again :)
              1. Thank you for everything. For the recap, go back to the top and read the posts (I'm not really sure how to summarize with words :) )