除了混合和匹配.c
和.cpp
文件之外,这是一个简单的Makefile - 但是,我并不确定它为什么不编译。我认为这是因为链接器错误,因为它只是抱怨网络类。你们中的任何一个让大师知道以下内容有什么问题?
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()'
答案 0 :(得分:3)
我猜你可能希望你的all
目标看起来像这样
all: server.o client.o cl_network.o
$(CC) $(CFLAGS) server.o cl_network.o -o server
$(CC) $(CFLAGS) client.o cl_network.o -o client