Makefile

Solved
next Posted messages 43 Registration date   Status Membre -  
next Posted messages 43 Registration date   Status Membre -
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 réponses

mamiemando Posted messages 33541 Registration date   Status Modérateur Last intervention   7 935
 
After each target, each command must be on a new line and preceded by a tabulation (not a series of spaces). For more information:
https://gl.developpez.com/tutoriel/outil/makefile/

Good luck
5
next Posted messages 43 Registration date   Status Membre 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
mamiemando Posted messages 33541 Registration date   Status Modérateur Last intervention   7 935
 
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.
0
next Posted messages 43 Registration date   Status Membre 1
 
What has changed between my code and the one you gave me?
0
next Posted messages 43 Registration date   Status Membre 1
 
I tried the code and now I have: *** missing separator. Stopped.
0
mamiemando Posted messages 33541 Registration date   Status Modérateur Last intervention   7 935
 
<5> Line breaks and tabs
<6> Did you use tabs correctly:
clean: <TAB>${RM} $(OBJS) *.c~ $(BIN): $(OBJS) <TAB>$(CC) $(LINKOBJET) -o $(BIN) $(LDFLAGS) ...
0
next Posted messages 43 Registration date   Status Membre 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 :)
0
mamiemando Posted messages 33541 Registration date   Status Modérateur Last intervention   7 935
 
Perfect, keep it up :-)
0
next Posted messages 43 Registration date   Status Membre 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 :) )
0