I have a large project with various constructors for custom classes that I have written. For each class exists a header file which contains the class definition and the constructors. In addition, a .cpp file exists for each class that contains the definition of the member functions for that class.
When I invoke make everything compiles fine into .o files. However, the linker complains of duplicate symbols for each of my constructors.
I have tried moving the definitions of the constructors to the .cpp files, but that has not solved my problem.
My makefile is as follows
CC=g++
CFLAGS=-c -Wall
LDFLAGS=
PRJ_SRC_DIR=./source
GENHEADER_DIR=/usr/local/include/genheaders
PRJ_SOURCES= #long list of .cpp files
GENERAL_SOURCES= #long list of .cpp files
SOURCES=$(PRJ_SOURCES:%=$(PRJ_SRC_DIR)/%) $(GENERAL_SOURCES:%=$(GENHEADER_DIR)/%)
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=networkMole.out
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE):$(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
.cpp.o:
$(CC) $(CFLAGS) $< -o $@
All of my constructors are declared within the body of a class and defined at the end of a class.
/* class1.hpp */
classOne{
/* Some Code */
ClassOne();
};
ClassOne::ClassOne(){ /*Code*/}