Compiling with GSL

M

Marcelo

Hello,

I am having somre problems with the GSL library from GNU. I am trying to do a
HelloWorld example but it doesn't link well.

#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;
}

and the command is
g++ -I/usr/local/include/gsl test.cpp -o test

but it doesn't work at all on Linux.
My GSL headers are in /usr/local/include/gsl and the error is

/tmp/cc4wOtbY.o: In function `main':
test.cpp:(.text+0x36): undefined reference to `gsl_sf_bessel_J0'
collect2: ld returned 1 exit status

Thanks a lot for your help.

Marcelo
 
?

=?iso-8859-1?q?Stephan_Br=F6nnimann?=

Marcelo said:
Hello,

I am having somre problems with the GSL library from GNU. I am trying to do a
HelloWorld example but it doesn't link well.

#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;
}

and the command is
g++ -I/usr/local/include/gsl test.cpp -o test

but it doesn't work at all on Linux.
My GSL headers are in /usr/local/include/gsl and the error is

/tmp/cc4wOtbY.o: In function `main':
test.cpp:(.text+0x36): undefined reference to `gsl_sf_bessel_J0'
collect2: ld returned 1 exit status

You must link with the GSL library, append something like -lgsl
(I don't know the exact library name, check the GSL documentation).

Regards, Stephan
 
K

Kai-Uwe Bux

Marcelo said:
Hello,

I am having somre problems with the GSL library from GNU. I am trying to
do a HelloWorld example but it doesn't link well.

#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;
}

and the command is
g++ -I/usr/local/include/gsl test.cpp -o test

but it doesn't work at all on Linux.
My GSL headers are in /usr/local/include/gsl and the error is

/tmp/cc4wOtbY.o: In function `main':
test.cpp:(.text+0x36): undefined reference to `gsl_sf_bessel_J0'
collect2: ld returned 1 exit status

The compiler finds the headers. But you need to tell the linker to reference
the actual precompiled library. The ways of doing this are platform
specific and off topic in this group. Very likely the documentation for
your compiler and the documentation for GSL contain information about what
you need to do. Since you mentioned Linux, I would guess that there is a
command line option that you forgot.


Best

Kai-Uwe Bux
 
M

Marcelo

Stephan said:
You must link with the GSL library, append something like -lgsl
(I don't know the exact library name, check the GSL documentation).

Regards, Stephan
thanks a lot,

i have found my problem with the -lgsl -lgslcblas -lm

MArcelo
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,785
Latest member
undedgini

Latest Threads

Top