0

I am completely new to Linux. I've just installed Ubuntu 16.04 on an old PC and I am trying to install the gsl library for a project. I ran

sudo apt install libgsl2, libgsl0-dev, libgsl-dev, gsl-bin

Then I made a gsltest.c test program with the code

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

int main (int argc, char *argv[])
{
  /* set up GSL RNG */
  gsl_rng *r = gsl_rng_alloc(gsl_rng_mt19937);
  /* end of GSL setup */

  int i,n;
  double gauss,gamma;  

  n=atoi(argv[1]);
  for (i=0;i<n;i++)
    {
      gauss=gsl_ran_gaussian(r,2.0);
      gamma=gsl_ran_gamma(r,2.0,3.0);
      printf("%2.4f %2.4f\n", gauss,gamma);
    }
  return(0);
}

I copied the code from somewhere on the internet and proceeded with the following command

gcc -Wall -I/home/myname/gsl/include -c gsltest.c

which throws an error:

gsltest.c:2:21: fatal error: gsl_rng.h: No such file or directory compilation terminated.

What am I doing wrong?

Zanna
  • 72,312

1 Answers1

4

If you installed libgsl-dev, then the headers should be in /usr/include/gsl/, hence the compiler should be able to locate them if you specify -I/usr/include/gsl

Or you can omit the -I directive altogether if you change your #includes to #include <gsl/gsl_randist.h> etc.

Alternatively, you might want to consider using pkg-config to locate the headers automatically e.g.

gcc -Wall `pkg-config --cflags gsl` -c gsltest.c
steeldriver
  • 142,475