This is the mail archive of the gsl-discuss@sourceware.cygnus.com mailing list for the GSL project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Problems with creating executables using GSL with RadHat Linux


Hello,

I wanted to try out GSL for some numerical equation solvers, but I am
running into problems generating an executable for even a simple example
code as given in
http://sourceware.cygnus.com/gsl/ref/gsl-ref_9.html#SEC88.  The
installation seamed to have gone fine, the 'make check' script returned
almost all tests passed except for the last portion (attached is a copy
of the make_check.log file).  However when I try to build an example
executable I get into problems.  Executing

    gcc -I/usr/local/include/gsl -c main.c

 seams to go fine, but when I do

      gcc -lgslroots -L/usr/local/lib/gsl main.o

I get the following errors:

[root@ash CS690]# gcc -lgslroots -L/usr/local/lib/gsl main.o
main.o: In function `main':
main.o(.text+0xf0): undefined reference to `sqrt'
main.o(.text+0x148): undefined reference to `gsl_root_fsolver_brent'
main.o(.text+0x14e): undefined reference to `gsl_root_fsolver_alloc'
main.o(.text+0x15f): undefined reference to `gsl_root_fsolver_name'
main.o(.text+0x1ae): undefined reference to `gsl_root_fsolver_iterate'
main.o(.text+0x1bf): undefined reference to `gsl_root_fsolver_root'
main.o(.text+0x1d2): undefined reference to `gsl_root_fsolver_interval'
main.o(.text+0x1f8): undefined reference to `gsl_root_test_interval'
collect2: ld returned 1 exit status

,even though the library file libgslroots.a seams to be loaded.  I also
did a 'grep' for some of the listed references and they are indeed
present in the libgslroots.a file.

I am attaching all three example files that I am trying to compile.
What could be the problem?!

Thanks for your help.



double quadratic (double x, void *params)
{
  struct quadratic_params *p = (struct quadratic_params *) params;

  double a = p->a;
  double b = p->b;
  double c = p->c;

  return (a * x + b) * x + c;
}

double quadratic_deriv (double x, void *params)
{
  struct quadratic_params *p = (struct quadratic_params *) params;

  double a = p->a;
  double b = p->b;
  double c = p->c;

  return 2.0 * a * x + b;
}

void
quadratic_fdf (double x, void *params, double *y, double *dy)
{
  struct quadratic_params *p = (struct quadratic_params *) params;

  double a = p->a;
  double b = p->b;
  double c = p->c;

  *y = (a * x + b) * x + c;
  *dy = 2.0 * a * x + b;
}




struct quadratic_params {double a, b, c;};
double quadratic (double x, void *params);
double quadratic_deriv (double x, void *params);
void quadratic_fdf (double x, void *params, double *y, double *dy);
#include <stdio.h>
#include <gsl_errno.h>
#include <gsl_math.h>
#include <gsl_roots.h>

#include "demof.h"
#include "demof.c"

int
main ()
{
  int status;
  int iterations = 0, max_iterations = 100;
  gsl_root_fsolver *s;
  double r = 0, r_expected = sqrt (5.0);
  gsl_interval x = {0.0, 5.0};
  gsl_function F;
  struct quadratic_params params = {1.0, 0.0, -5.0};

  F.function = &quadratic;
  F.params = &params;

  s = gsl_root_fsolver_alloc (gsl_root_fsolver_brent, &F, x);

  printf ("using %s method\n", gsl_root_fsolver_name (s));

  printf ("%5s [%9s, %9s] %9s %9s %10s %9s\n",
          "iter", "lower", "upper", "root", "actual", "err", "err(est)");

  do
    {
      iterations++;
      status = gsl_root_fsolver_iterate (s);
      r = gsl_root_fsolver_root (s);
      x = gsl_root_fsolver_interval (s);
      status = gsl_root_test_interval (x, 0, 0.001);

      if (status == GSL_SUCCESS)
        printf ("Converged:\n");

      printf ("%5d [%.7f, %.7f] %.7f %.7f %+.7f %.7f\n",
              iterations, x.lower, x.upper,
              r, r_expected, r - r_expected, x.upper - x.lower);
    }
  while (status == GSL_CONTINUE && iterations < max_iterations);

}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]