This is the mail archive of the
gsl-discuss@sources.redhat.com
mailing list for the GSL project.
Re: to compile a simple program with gsl
- From: Achim Gaedke <achim at zpr dot uni-koeln dot de>
- To: Mael Guillemot <Mael dot Guillemot at idiap dot ch>
- Cc: gsl-discuss at sources dot redhat dot com
- Date: Mon, 11 Mar 2002 15:37:02 +0100 (MET)
- Subject: Re: to compile a simple program with gsl
Maybe this is a very old version of gsl (in Version 0.5 or so it was
necssary). Please send the version number or the time of this tutorial.
In newer versions the shell command gsl-config --libs gives you the
necessary flags.
Look out for the tutorial on the gsl homepage.
Achim
Achim Gaedke, ZPR
Weyertal 80, 50931 Köln
Tel: +49 221 470 6021
On Mon, 11 Mar 2002, Mael Guillemot wrote:
> Hello "gsl-users",
>
> I have recently installed the gsl library.
>
> Could anyone show me the command for compiling a simple program (demo.c
> here)?
>
> Instead of typing:
>
> gcc -I/usr/local/include/gsl -L/usr/local/lib/gsl demo.c -lgslrandist
> -lgslrng -lgslspecfunc -lgslerr -lm
>
> As I have redirected the library paths, i write:
>
> gcc -I/home/vision/guillemo/local/include/gsl
> -L/home/vision/guillemo/local/lib/gsl demo.c -lgslrandist -lgslrng
> -lgslspecfunc -lgslerr -lm
>
> This message appears:
> =============================================================
> /usr/local/sparc-sun-solaris2.7/bin/ld: cannot open -lgslrng: No such
> file or directory
> collect2: ld returned 1 exit status
> =============================================================
>
> I do not understand the objective to put "-lgslrandist -lgslrng
> -lgslspecfunc -lgslerr" in the command line. If you see my problem,
> thanks a lot for replying me,
>
> Mael
>
>
>
>
> /* demo.c
> Random Number Distribution Examples
> ===================================
>
> The following program demonstrates the use of a random number
> generator to produce variates from a distribution. It prints 10 samples
> from the Poisson distribution with a mean of 3.
>
> */
>
>
> #include <stdio.h>
> #include <gsl_rng.h>
> #include <gsl_randist.h>
>
> int
> main ()
> {
> 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();
>
> r = gsl_rng_alloc (gsl_rng_default);
>
> /* 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");
> }
>
>
> /*
> Compilation:
> ============
>
> If the library and header files are installed under `/usr/local' (the
> default location) then the program can be compiled with these options,
>
> gcc -I/usr/local/include/gsl -L/usr/local/lib/gsl demo.c
> -lgslrandist
> -lgslrng -lgslspecfunc -lgslerr -lm
>
>
> Outputs:
> ========
>
> Here is the output of the program,
>
> $ ./a.out
> 4 2 3 3 1 3 4 1 3 5
>
> The variates depend on the seed used by the generator. The seed for the
> default generator type `gsl_rng_default' can be changed with the
> `GSL_RNG_SEED' environment variable to produce a different stream of
> variates,
>
> $ GSL_RNG_SEED=123 ./a.out
> GSL_RNG_SEED=123
> 1 1 2 1 2 6 2 1 8 7
> */
>
>
>
>