Other than mixing and matching .c
and .cpp
files, this is a simple Makefile -- yet, I'm not really sure why it's not compiling. I assume it's because of a linker error since it's only complaining about the network class. Any one of you Make gurus know what's wrong with the following?
CC=g++
DEBUG=-g
CFLAGS=$(DEBUG) -Wall -D_POSIX_C_SOURCE -pthread -std=c++0x
HEADERS=cl_network.h
%.o: %.c $(HEADERS)
$(CC) $(CFLAGS) $< -o $@
all: server.o client.o cl_network.o
$(CC) $(CFLAGS) server.o -o server
$(CC) $(CFLAGS) client.o -o client
$(CC) $(CFLAGS) cl_network.o -o cl_network
client.o: client.cpp cl_network.h
$(CC) $(CFLAGS) -c client.cpp
server.o: server.c
$(CC) $(CFLAGS) -c server.c
cl_network.o: cl_network.cpp cl_network.h
$(CC) $(CFLAGS) -c cl_network.cpp
.PHONY: clean
clean:
rm server.o server client.o client cl_network cl_network.o
Errors:
client.cpp:49: undefined reference to `cl_network::cl_network(char*)'
client.cpp:50: undefined reference to `cl_network::connectToServer()'
client.cpp:63: undefined reference to `cl_network::~cl_network()'
client.cpp:63: undefined reference to `cl_network::~cl_network()'