我正在尝试让我的 makefile 工作,但它给了我一些错误,我无法让它工作。
OBJS = Kmeans.o cluster.o data.o
CC = g++
DEBUG = -g
CFLAGS = -Wall -c $(DEBUG)
LFLAGS = -Wall $(DEBUG)
clustering : $(OBJS)
$(CC) $(LFLAGS) $(OBJS) -o clustering
Kmeans.o : Kmeans.h Kmeans.cpp cluster.h data.h
$(CC) $(CFLAGS) Kmeans.cpp
cluster.o : cluster.h cluster.cpp data.h
$(CC) $(CFLAGS) cluster.cpp
data.o : data.h data.cpp
$(CC) $(CFLAGS) data.cpp
clean:
\rm *.o *~ clustering
文件是:
clustering.cpp -> #include "Kmeans.h"
Kmeans.cpp -> #include "Kmeans.h"
Kmeans.h -> #include "cluster.h"
cluster.cpp -> #include "cluster.h"
cluster.h -> #include "data.h"
data.cpp -> #include "data.h"
我究竟做错了什么?
编辑:对不起,我忘了包括错误:
Kmeans.o: In function `Kmeans::read(char*)':
Kmeans.cpp:(.text+0x53c): undefined reference to `Data::~Data()'
cluster.o: In function `Cluster::Cluster(int, int, int)':
cluster.cpp:(.text+0x45): undefined reference to `Data::~Data()'
cluster.cpp:(.text+0x80): undefined reference to `Data::~Data()'
cluster.o: In function `Cluster::Cluster()':
cluster.cpp:(.text+0xca): undefined reference to `Data::~Data()'
cluster.cpp:(.text+0x110): undefined reference to `Data::~Data()'
cluster.o: In function `Cluster::setData(int, int, int)':
cluster.cpp:(.text+0x158): undefined reference to `Data::~Data()'
collect2: ld devolvió el estado de salida 1
make: *** [clustering] Error 1
谢谢!
我编译每个文件,问题出在最后一行:
g++ -c -o clustering.o clustering.cpp
g++ -c -o data.o data.cpp
g++ -c -o Kmeans.o Kmeans.cpp
g++ -c -o cluster.o cluster.cpp
g++ -o clustering clustering.o data.o Kmeans.o cluster.o <----