Results 1 to 4 of 4

Thread: Gsl

  1. #1
    Join Date
    Mar 2010
    Beans
    122

    Gsl

    Hi everybody,

    So I recently installed gsl library using sudo apt-get install libgsl0-dev.

    I use a simple example
    #include <stdio.h>
    #include <gsl/gsl_rng.h>
    #include <gsl/gsl_randist.h>

    int
    main (void)
    {
    const gsl_rng_type * T;
    gsl_rng * r;

    int i, n = 10;
    double mu = 3.0;

    /* create a generator chosen by the
    environment variable GSL_RNG_TYPE */

    gsl_rng_env_setup();

    T = gsl_rng_default;
    r = gsl_rng_alloc (T);

    /* print n random variates chosen from
    the poisson distribution with mean
    parameter mu */

    for (i = 0; i < n; i++)
    {
    unsigned int k = gsl_ran_poisson (r, mu);
    printf (" %u", k);
    }

    printf ("\n");
    gsl_rng_free (r);
    return 0;
    }
    and using g++ -o exe_file -lgsl file.cpp
    but I get the following errors
    A.cpp.text+0x1e): undefined reference to `gsl_rng_env_setup'
    A.cpp.text+0x25): undefined reference to `gsl_rng_default'
    A.cpp.text+0x35): undefined reference to `gsl_rng_alloc'
    A.cpp.text+0x53): undefined reference to `gsl_ran_poisson'
    A.cpp.text+0x91): undefined reference to `gsl_rng_free'
    Any help is appreciated.

  2. #2
    Join Date
    Mar 2010
    Beans
    122

    Re: Gsl

    By the way I am using Ubuntu 11.10.

  3. #3
    Join Date
    Jul 2011
    Beans
    2

    Re: Gsl

    Having the same issue on 11.10. Any help would be much appreciated.

  4. #4
    Join Date
    Jul 2011
    Beans
    2

    Re: Gsl

    Actually just found the solution.
    Basically, you have to put the compiler flags in the correct order. That is, after the compile statement:

    Code:
    $ gcc temp.c -o temp -lgsl -lgslcblas
    Background:
    <a href="http://askubuntu.com/questions/71623/why-does-gsl-library-not-compile-link-in-11-10-despite-that-it-did-under-11-04">http://askubuntu.com/questions/71623/why-does-gsl-library-not-compile-link-in-11-10-despite-that-it-did-under-11-04</a>

    and
    <a href="http://ubuntuforums.org/archive/index.php/t-1833136.html">http://ubuntuforums.org/archive/index.php/t-1833136.html</a>

    HTH

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •