Compiling with GSL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Marcelo

    #1

    Compiling with GSL

    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_J 0 (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
  • Stephan Brönnimann

    #2
    Re: Compiling with GSL

    Marcelo wrote:[color=blue]
    > 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_J 0 (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[/color]

    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

    Comment

    • Kai-Uwe Bux

      #3
      Re: Compiling with GSL

      Marcelo wrote:
      [color=blue]
      > 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_J 0 (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[/color]

      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

      Comment

      • Marcelo

        #4
        Re: Compiling with GSL

        Stephan Brönnimann wrote:[color=blue]
        > Marcelo wrote:
        >[color=green]
        >>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_J 0 (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:(.te xt+0x36): undefined reference to `gsl_sf_bessel_ J0'
        >>collect2: ld returned 1 exit status[/color]
        >
        >
        > 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
        >[/color]
        thanks a lot,

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

        MArcelo

        Comment

        Working...