Reputation: 331
I've done this Makefile with the following structure:
BIN_FILES = array cliente servidor
CC = gcc
CCGLAGS = -Wall -g
all: CFLAGS=$(CCGLAGS)
all: $(BIN_FILES)
.PHONY : all
array.o: array.c array.h
$(CC) -c -Wall -fPIC array.c
cliente.o: cliente.c array.h
$(CC) -Wall -c cliente.c
cliente: cliente.o array.h
$(CC) -Wall -o cliente -ldl -lrt
servidor.o: servidor.c mensajes.h
$(CC) -Wall -c servidor.c -lrt -lpthread
servidor: servidor.o
$(CC) -o $@ servidor -lrt -lpthread
clean:
rm -f $(BIN_FILES) *.o
.SUFFIXES:
.PHONY : clean
But when I try to execute it, it only works the first rule. Then the execution stops. My final objective is to make each rule work, because if I execute each rule separately it works:
gcc -c -Wall -fPIC array.c
gcc -fPIC -shared -o libarray.so array.o -lrt
gcc -Wall -o cliente cliente.c -ldl -lrt
gcc -Wall -o servidor servidor.c -lrt -lpthread
Thanks
Edit: Now I obtain the following error applying @Jens modifications:
make: *** No rule to make the objective 'array', necesary for 'all'. Stop.
Upvotes: 2
Views: 910
Reputation: 72747
The targets for cliente.o and servidor.o should use -c
instead of -o
, i.e. you want to compile to object files.
There's also no point in specifying header files as dependencies in targets cliente and servidor. The commands for these only link, but don't compile files.
servidor: servidor.o
$(CC) -o $@ servidor.o -lrt -lpthread
There's also no point is specifying library options -ldl
etc when compiling to object files with -c
.
cliente.o: cliente.c array.h
$(CC) -Wall -c cliente.c
Upvotes: 1