So, in the course of a bigger project, I need to generate normally distributed random numbers. I've decided to try to use the GSL rng library.
From the gsl webpage I got an example code, just to get an idea of how the interface works.
The program looks like:
#include <iostream>
#include <gsl_rng.h>
int main(){
const gsl_rng_type * T;
gsl_rng * r;
int i, n = 10;
gsl_rng_env_setup();
T = gsl_rng_default;
r = gsl_rng_alloc (T);
for (i = 0; i < n; i++)
{
double u = gsl_rng_uniform(r);
printf ("%.5f\n", u);
}
gsl_rng_free (r);
return 0;
}
and the output when compiling is:
g++ -Wall -I /usr/include/gsl -o main.exe main.cpp
/tmp/ccId4VRU.o: In function `main':
main.cpp:(.text+0x10): undefined reference to `gsl_rng_env_setup'
main.cpp:(.text+0x17): undefined reference to `gsl_rng_default'
main.cpp:(.text+0x27): undefined reference to `gsl_rng_alloc'
main.cpp:(.text+0x40): undefined reference to `gsl_rng_uniform'
main.cpp:(.text+0x76): undefined reference to `gsl_rng_free'
collect2: ld returned 1 exit status
make: *** [main.exe] Error 1
Now clearly the compiler did find some things that it needed, otherwise I would have gotten errors from declaring r and T, for instance. Indeed, this also happens if I remove the ".h" from the #include-command.
So, why doesn't it have all the commands?
Should I be considering using a library written specifically for c++ rather than c (have boost in mind)? Should I be thinking of updating my gsl installation? I only got Linux within the last few months, so I wouldn't think GSL had changed much since I installed it.
Helpful comments will be much appreciated =)