help-gsl
[Top][All Lists]
Advanced

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

[Help-gsl] compiling under fedora core 5


From: Fred J.
Subject: [Help-gsl] compiling under fedora core 5
Date: Tue, 31 Oct 2006 01:48:43 -0800 (PST)

Dear users, 
I installed the gsl files under linux fedora core 5, after reading the docs it 
does not appear to me how to compile and link the following program which thus 
gives the afterwards errors, 

thanks for you help

here is the make file 
#LDFLAGS = -lposix
CXXFLAGS = -gdwarf-2
OBJS := $(patsubst %.cpp,%.o,$(wildcard *.cpp))
COMP = g++

proj: $(OBJS)
    $(COMP) -Wall -gdwarf-2 -o proj $(OBJS) #$(LDFLAGS)
 
#-Wall turns on all warnings
#-gdwarf-2 for dubugging note gdb manual 12.4.1
clean: 
    rm -rf *.o proj


************************ error *****************************
make -k 
g++ -Wall -gdwarf-2 -o proj main.o #
main.o: In function `main':
/home/fred/myProg/try/main.cpp:67: undefined reference to `gsl_rng_env_setup'
/home/fred/myProg/try/main.cpp:69: undefined reference to `gsl_rng_default'
/home/fred/myProg/try/main.cpp:70: undefined reference to `gsl_rng_alloc'
/home/fred/myProg/try/main.cpp:83: undefined reference to `gsl_siman_solve'
main.o: In function `S1(gsl_rng const*, void*, double)':
/home/fred/myProg/try/main.cpp:49: undefined reference to `gsl_rng_uniform'
collect2: ld returned 1 exit status
make: *** [proj] Error 1


******************************* code **********************************
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <gsl/gsl_siman.h>
     
/* set up parameters for this simulated annealing run */
     
/* how many points do we try before stepping */
#define N_TRIES 200             
     
/* how many iterations for each T? */
#define ITERS_FIXED_T 10        
     
/* max step size in random walk */
#define STEP_SIZE 10            
     
/* Boltzmann constant */
#define K 1.0                   
     
/* initial temperature */
#define T_INITIAL 0.002         
     
/* damping factor for temperature */
#define MU_T 1.005              
#define T_MIN 2.0e-6
     
gsl_siman_params_t params 
= {N_TRIES, ITERS_FIXED_T, STEP_SIZE,
   K, T_INITIAL, MU_T, T_MIN};
     
/* now some functions to test in one dimension */
double E1(void *xp)
{
  double x = * ((double *) xp);
  return exp(-pow((x-1.0),2.0))*sin(8*x);
}
     
double M1(void *xp, void *yp)
{
  double x = *((double *) xp);
  double y = *((double *) yp);
  return fabs(x - y);
}
     
void S1(const gsl_rng * r, void *xp, double step_size)
{
  double old_x = *((double *) xp);
  double new_x;
  double u = gsl_rng_uniform(r);
  new_x = u * 2 * step_size - step_size + old_x;
  memcpy(xp, &new_x, sizeof(new_x));
}
     
void P1(void *xp)
{
  printf ("%12g", *((double *) xp));
}
     
int
main(int argc, char *argv[])
{
  const gsl_rng_type * T;
  gsl_rng * r;
     
  double x_initial = 15.5;
     
  gsl_rng_env_setup();
     
  T = gsl_rng_default;
  r = gsl_rng_alloc(T);
     
  gsl_siman_solve(r,        // const gsl_rng *, for steps generation
          &x_initial,     // void *, points to starting configuration and best 
results once finished
          E1,         // gsl_siman_Efunc_t, specifies the space to search
          S1,         // gsl_siman_step_t, for steps generation
          M1,         
          P1,        // gsl_siman_print_t, if NULL (no print out), else stdout
          NULL,     // gsl_siman_copy_t, copyfunc, 
          NULL,     // gsl_siman_copy_construct_t, copy_constructor
          NULL,     // gsl_siman_destroy_t, destructor
          sizeof(double), // size_t, fixed size "updating configuration mode", 
zero in the variable-size mode
          params    // gsl_siman_params_t, 
          );
  return 0;
}


 
---------------------------------
 Check out the New Yahoo! Mail - Fire up a more powerful email and get things 
done faster. 


reply via email to

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