I have a project using functions from a class CRandomMersenne, declared in header randomc.h; the functions are defined in a different file mersenne.cpp. In my makefile I have an object *MC_funcs2.o* that uses functions from the class. The source *MC_funcs2.cpp* includes the header randomc.h. However the compiler complains:
MC_funcs2.o:MC_funcs2.cpp:(.text+0x20): undefined reference to `CRandomMersenne::Random()'
I understand there is something I've done wrong with declaring functions outside the class definition, including header file to use mentioned functions and maybe with the linking in the makefile. Here is a stripped down version of some of the files:
makefile:
SpMC3: SpMC3.cpp SpMC.h mersenne.o MC_funcs2.o
g++ SpMC3.cpp MC_funcs2.o mersenne.o -o SpMC3
MC_funcs2.o: MC_funcs2.cpp SpMC.h randomc.h
g++ -c MC_funcs2.cpp mersenne.cpp
mersenne.o: mersenne.cpp randomc.h userintf.cpp
g++ -c mersenne.cpp userintf.cpp
SpMC3.cpp (main program):
#include "SpMC.h"
int main() {
cout << "boing" << endl;
return 0;
}
MCfuncs2.cpp (the one that doesn't compile):
#include "SpMC.h"
#include "randomc.h"
CRandomMersenne RanGen(time(0));
void outrandom() {
ofstream out;
out << RanGen.Random() << endl;
return;
}
Any ideas?