I'm working on this NeuralNet class:
class NeuralNet {
public:
// Public functions
private:
vectors vect; // Point-of-access for functions in class vectors
// Private functions
};
And I'm using this extremely simple makefile:
all: nnet.exe
nnet.exe: main.o neuralnet.o vectors.o
g++ -o nnet.exe main.o vectors.o neuralnet.o
main.o: main.cpp neuralnet.h
g++ -ggdb -c main.cpp
vectors.o: vectors.cpp vectors.h
g++ -ggdb -c vectors.cpp
neuralnet.o: neuralnet.cpp neuralnet.h vectors.h
g++ -ggdb -c neuralnet.cpp
clean:
rm -f *.o nnet.exe
When g++ gets run to build the final executable, I get a lot of errors in the following form:
neuralnet.o: /path/to/neuralnet.cpp: line# : undefined reference to vectors::fn_name(args)
For example, I have defined a function:
template<typename T> void fill_vec(vector<T>&, int, double);
When I call this function I pass a variable declared with type vector<double>
for the first argument, and the linker reports undefined reference to void vectors::fill_vec<double>(std::vector<double, std::allocator<double> >&, int, double)
All calls to functions of class vectors
in the implementation of NeuralNet
are called from vect
. However, both neuralnet.cpp and neuralnet.h contain includes for "vectors.h", so I'm assuming that I'm somehow linking incorrectly.
Does anyone see anything obvious?