I have this code here in a header file and source files. Here are little snippets of the code. This is from the .cpp
file.
int sample(Cdf* cdf)
{
//double RandomUniform();
double r = RandomUniform(); //code that is causing the error
for (int j = 0; j < cdf->n; j++)
if (r < cdf->vals[j])
return cdf->ids[j];
// return 0;
}
This is from the .c
file:
double RandomUniform(void)
{
double uni;
/* Make sure the initialisation routine has been called */
if (!test)
RandomInitialise(1802,9373);
uni = u[i97-1] - u[j97-1];
if (uni <= 0.0)
uni++;
u[i97-1] = uni;
i97--;
// ...
}
And this is from my header file
void RandomInitialise(int,int);
double RandomUniform();
double RandomGaussian(double,double);
int RandomInt(int,int);
double RandomDouble(double,double);
I have used #include "headerfile.h"
in the .cpp
file and then I compiled the code. As you can see from the snippets, I am basically calling the function RandomUniform()
that is in the .cpp
file then defining it in the header file.
Problem is, whenever I build the program, I get an "undefined reference to function" error. Here is the error I am getting
In function 'Z6sampleP3Cdf':
undefined reference to 'RandomUniform()'
Anybody have any idea?