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
  • 70,465

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
  • 136,215
  • 21
  • 243
  • 336
  • Nice! Thank you so much! I added the gsl/gsl... to my includes, omitted the -I part and then went ahead with the command $ gcc -L/usr/local/lib example.o -lgsl -lgslcblas -lm' which worked! – noobieboobie May 13 '17 at 07:56