I'm trying to run 2 simple examples in c/c++ using the GNU Scientific Library.
That are the codes:
1st: An Example Program
#include <stdio.h>
#include <gsl/gsl_sf_bessel.h>
int main (void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}
2nd: Example programs for matrices
#include <stdio.h>
#include <gsl/gsl_matrix.h>
int main (void)
{
int i, j;
gsl_matrix * m = gsl_matrix_alloc (10, 3);
for (i = 0; i < 10; i++)
for (j = 0; j < 3; j++)
gsl_matrix_set (m, i, j, 0.23 + 100*i + j);
for (i = 0; i < 100; i++) /* OUT OF RANGE ERROR */
for (j = 0; j < 3; j++)
printf ("m(%d,%d) = %g\n", i, j,
gsl_matrix_get (m, i, j));
gsl_matrix_free (m);
return 0;
}
I saw on the Software Center that I have the GNU Scientific Library (GSL) - Library package (libgsl0ldbl 1.16+dfsg-1ubuntu1) but the documentation that I read said that I needed to compile with the next code:
$ gcc -Wall -I/usr/local/include -c example.c
And directory /usr/local/include
was empty so recently I have also installed manually from the site Main GSL - GNU Scientific Library site the new version GSL2.1. Next I run the code before mentioned so I had a new file example.o then I run the next code:
$ gcc -L/usr/local/lib example.o -lgsl -lgslcblas -lm
So I had a a.out
file, I tried to run $ ./a.out
but the output was:
`./a.out: error while loading shared libraries: libgsl.so.19: cannot open shared object file: No such file or directory`
I tried this command too:
$ ldconfig -p | grep gsl
libgslcblas.so.0 (libc6,x86-64) => /usr/lib/libgslcblas.so.0
libgsl.so.0 (libc6,x86-64) => /usr/lib/libgsl.so.0
So I can see that the excecution of a.out
was asking for libgsl.so.19
but the ldconfig said that the library on the pc is libgsl.so.19
libgsl.so.19
in thelibgsl2
package. But if you've installed manually, check ifsudo ldconfig
helps to update the library lookup cache or try to specify the search path manually when launching:LD_LIBRARY_PATH=/usr/local/lib ./a.out
sudo apt-get install gsl-bin
and thengcc example.c -lgsl -lgslcblas -lm
sudo ldconfig
.