I have a project with the following files, all in the same folder
client.c
server.c
reliable_udp.h
reliable_udp.c
conf.h
Among the other libraries, client.c
includes also reliable_udp.h
( #include "reliable_udp.h"
) in order to use the functions packet_send
and print_conf
(that are implemented in reliable_udp.c
).
I'm new to Makefile
s, and I'm trying to write one:
CC = gcc
CFLAGS = -Wall -Wextra -Wpedantic -O3
SRC = client.c server.c
OBJ = $(SRC:.c=.o)
all: $(OBJ)
${CC} ${CLFAGS} client.o -o client
${CC} ${CLFAGS} server.o -o server
client.o: reliable_udp.h
clean:
rm -f *.o core
cleanall:
rm -f *.o core client server
If I try to run make
, I get the following output:
gcc -Wall -Wextra -Wpedantic -O3 -c -o client.o client.c
gcc client.o -o client
client.o: In function `main':
client.c:(.text.startup+0x84): undefined reference to `packet_send'
client.c:(.text.startup+0x8b): undefined reference to `print_conf'
collect2: error: ld returned 1 exit status
Makefile:7: recipe for target 'all' failed
make: *** [all] Error 1
Obviously I'm failing writing correctly the Makefile
. How should I fix it? Why am I getting this error?