This works without a hitch on Ubuntu 13.04:
edd@max:~/src/progs/C$ cat gsl_bessel.c
// cf http://stackoverflow.com/questions/18588607/g-unable-to-link-libgsl
#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;
}
edd@max:~/src/progs/C$ gcc -Wall -o gsl_bessel gsl_bessel.c -lgsl -lgslcblas -lm
edd@max:~/src/progs/C$ ./gsl_bessel
J0(5) = -1.775967713143382642e-01
edd@max:~/src/progs/C$
Maybe reinstall / check the packages? They have not changed in a long while.
(Disclaimer: I happen to be the Debian maintainer behind these packages.)
Edit: Oh, re-reading your title and tags, your mistake is the use of g++
instead of gcc
. This is a C library, and you wrote a C program. It works with C++ but you need extern "C"
(which is a different topic).
Edit 2: Never mind. Works fine with g++
as well here as the headers are C++ ready:
edd@max:~/src/progs/C$ rm ./gsl_bessel
edd@max:~/src/progs/C$ g++ -Wall -o gsl_bessel gsl_bessel.c -lgsl -lgslcblas -lm
edd@max:~/src/progs/C$ ./gsl_bessel
J0(5) = -1.775967713143382642e-01
edd@max:~/src/progs/C$