help-gsl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-gsl] Random generator: linking problem


From: Marco Tului
Subject: [Help-gsl] Random generator: linking problem
Date: Mon, 11 May 2009 17:02:57 +0200

Hi all,
excuse me, I'm trying to compile a random generator C++ class for my
library, in which I use the GSL. But even tough I compile without errors my
hpp/cpp, when in a test main file I try to instantiate an object of it, I
have these linking errors:

::::::::::::::::::::::::::::::::::::::::::::::
/usr/bin/ld: Undefined symbols:
_gsl_rng_alloc
_gsl_rng_default
_gsl_rng_free
collect2: ld returned 1 exit status
make: *** [default] Error 1
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

I have read the GSL manual, and in my Makefile I wrote:

:::::::::::::::::::::::
# RANDOM_NUMBER_GENERATOR
random_generator.o: random_generator.hpp random_generator.cpp
g++ -c random_generator.cpp -lgsl -lgslcblas -lm
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

as it seemed me correctly, so, why that? The hpp of my class is:

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
#ifndef RANDOM_GENERATOR__HPP
#define RANDOM_GENERATOR__HPP


#include <gsl/gsl_rng.h> // here we use the "GNU Scientific Library" (GSL)
to obtain a random number
#include <gsl/gsl_randist.h> // to obtain gsl_ran_gaussian()
#include <iostream>
using namespace std;


enum Distribution_type {
  NORMAL = 1,
  UNIFORM = 2,
  BINARY = 3
};


class Random_generator {

  private:
    const gsl_rng_type *_type_gen;
    gsl_rng *_gen; // 'gen' is the (random) generator

    Distribution_type _distr_type;


  public:
    // default CONSTRUCTOR
    Random_generator( ) {
      _type_gen = gsl_rng_default;
      _gen = gsl_rng_alloc(_type_gen); // in this way we allocate, in the
standard way, the generator 'gen'
    };

    // DESTRUCTOR
    ~Random_generator( ) {
        gsl_rng_free(_gen); // we free the memory associated with the
generator 'r'
    };


    double Get_rnd_generator( ) const { // by default we assume
Distribution_type = NORMAL
      return gsl_ran_gaussian(_gen, 1);
    };

    double Get_rnd_generator(Distribution_type distr_type_init) const {
      if(distr_type_init == NORMAL) {
        return gsl_ran_gaussian(_gen, 1);
      }
      else if(distr_type_init == UNIFORM) {
        // vv return sample da distribuzione uniforme...
      }
      else if(distr_type_init == BINARY) {
        // vv return sample da distribuzione binaria...
      }
    };


};


#endif
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::


The cpp file simply include that hpp. By the way, I've installed and
compiled my GSL (with shared libraries option etc.) on my Mac Os 10.4.11.




Thanks in advance, bye.

Marco Tului.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]