-1

The computer is refusing to run programs including GSL functions, despite the program compiling successfully. For example, consider the following program given as an example on the GSL website:

// Test program for GSL RNG

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

int main (void)
{
  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;
}

This compiles, but then gives the following error during execution:

/tmp/ccPWUHlO.o: dans la fonction « main »:
GSL_rng_test.cc:(.text+0x10): référence indéfinie vers « gsl_rng_env_setup »
GSL_rng_test.cc:(.text+0x17): référence indéfinie vers « gsl_rng_default »
GSL_rng_test.cc:(.text+0x27): référence indéfinie vers « gsl_rng_alloc »
GSL_rng_test.cc:(.text+0x46): référence indéfinie vers « gsl_rng_uniform »
GSL_rng_test.cc:(.text+0x7d): référence indéfinie vers « gsl_rng_free »
collect2: erreur: ld a retourné 1 code d'état d'exécution

Sorry, it's in French, but I think you will understand the gist. GSL is installed and I have checked for the existence of the header file myself. Can someone help?

  • C != C++, and your title specifies C while your `.cc` files extension would seem to indicate C++. In general, you should tag only the language you are writing/compiling unless you are asking a question regarding differences or similarities. – crashmstr Mar 07 '16 at 14:05

2 Answers2

1

It seems you did not link the GSL library properly. For example, if the relative path of your GSL library is LIB_GSL, and if you'd like to statically link the GSL library, you need to include a line that looks like this (tested for GSL 1.16)

LIB_GSL/.libs/libgsl.a

In case you also use BLAS functionality and do not link any other BLAS library on your own, you should also link with the BLAS library that is included in GSL, which would look something like this in case that you link statically (tested for GSL 1.16):

LIB_GSL/cblas/.libs/libgslcblas.a
sperber
  • 661
  • 6
  • 20
0

It seems your program wasn't linked properly. If the GSL library is installed at the default location /usr/local/lib, then may be the supporting library is missing (CBLAs library). GSL also provides a library for it (if your system doesn't) called libgslcblas.a.

Try linking your program with :

$ gcc -L<location_of_lib> yourProgram.o -lgsl -lgslcblas -lm

-With the -L option, provide the location of the library, it's not required if it's installed at the default location.

rogme
  • 84
  • 2