0

I copied the following code from the official gnu manual for random number generator:

#include <stdio.h>
#include <gsl/gsl_rng.h>
#include <gsl/gsl_randist.h>


int main (void)
{
  const gsl_rng_type * T;
  gsl_rng * r;

  int i, n = 10;
  double mu = 3.0;

  /* create a generator chosen by the 
     environment variable GSL_RNG_TYPE */

  gsl_rng_env_setup();

  T = gsl_rng_default;
  r = gsl_rng_alloc (T);

  /* print n random variates chosen from 
     the poisson distribution with mean 
     parameter mu */

  for (i = 0; i < n; i++) 
    {
      unsigned int k = gsl_ran_poisson (r, mu);
      printf (" %u", k);
    }

  printf ("\n");
  gsl_rng_free (r);
  return 0;
}

and I added the according lib-directory, bin-directory and include-directory to my DevCpp-project (and this appears to work fine, since before that, DevCpp couldn't even find those files). When I try to compile these files, however, I get the following errors:

[Linker error] undefined reference to 'gsl_rng_env_setup'
[Linker error] undefined reference to 'gsl_rng_default'

...and even more, all probably referring to functions defined within gsl_rng and gsl_randist. Also, declaring gsl_rng_env_setup before main(void) etc. doesn't help (then I get ambiguities). Do you know how to solve the problem? I use Windows 7, 64bit-system and DevCpp for compiling C/C++ code. I really even tried different ways of building the gsl-library (e.g. building from source, and then, when I had this error, using the unofficial Windows installer), but none of the methods solved this problem.

6
  • You added the directories, but did you specify what libraries to use? May 17, 2017 at 5:28
  • Well, there is no way (that I know of) to tell DevCpp to use a specific library (according to the link you gave). One can just add library paths. However, what I also just did was adding the files in the \bin from my gsl-distribution to the \bin of DevCpp (in the hope that DevCpp will then be able to use them maybe), but it also didn't work.
    – Yinyue
    May 17, 2017 at 5:45
  • @Yinyue, please just read the link provided above, then write your comment. There are ways to tell DevCpp to use a specific library
    – avatli
    May 17, 2017 at 6:04
  • @AliVolkanATLI I read the link, looked up an analogous way for DevCpp and then concluded that I know no/couldn't find any way for DevCpp to do it that way (maybe because I'm too stupid), but if you know how to tell DevCpp then I'd be very thankful if you told me.
    – Yinyue
    May 17, 2017 at 14:59
  • 1
    @Yinyue in every project in which you want to use a library, do Project > Project Options > Parameters > Add Library
    – avatli
    May 19, 2017 at 10:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.