I am trying to get my makefile working, but it is giving me some errors and I can’t get it to work.
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
And the files are:
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"
What am I doing wrong?
Edit:
Sorry, I forgot to include the errors:
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
Thanks!
I compile each file and the problem is in the last line:
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 <----
It seems that you have
Data::~Datadeclaration indata.hand you do not have definition anywhere.Just remove the declaration from header or add empty definition it it’s a virtual destructor.