Menu

GSL root finding : link problem with VC 8.0

Help
2006-06-12
2012-07-26
  • Nobody/Anonymous

    Hi,

    I have been using GSL with VC++.
    I haven't been facing any problem with my configuration of VC++ until I tried to use the root finder.
    When I try to compile the GSL exemple (using the Brent Root finder), I receive the error message :

    libgsl.a(roots_brent.o) : error LNK2019: unresolved external symbol _finite referenced in function _brent_init

    Does anybody have an idea of what I should do ?
    Many thanks.

    Here is the exemple I am tring to compile :

    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);
    

    We place the function definitions in a separate file (demo_fn.c),

    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;
     }
    

    The first program uses the function solver gsl_root_fsolver_brent for Brent's method and the general quadratic defined above to solve the following equation,

    with solution x = \sqrt 5 = 2.236068...

    include <stdio.h>

     #include &lt;gsl/gsl_errno.h&gt;
     #include &lt;gsl/gsl_math.h&gt;
     #include &lt;gsl/gsl_roots.h&gt;
    
     #include &quot;demo_fn.h&quot;
     #include &quot;demo_fn.c&quot;
    
     int
     main (void)
     {
       int status;
       int iter = 0, max_iter = 100;
       const gsl_root_fsolver_type *T;
       gsl_root_fsolver *s;
       double r = 0, r_expected = sqrt (5.0);
       double x_lo = 0.0, x_hi = 5.0;
       gsl_function F;
       struct quadratic_params params = {1.0, 0.0, -5.0};
    
       F.function = &amp;quadratic;
       F.params = &amp;params;
    
       T = gsl_root_fsolver_brent;
       s = gsl_root_fsolver_alloc (T);
       gsl_root_fsolver_set (s, &amp;F, x_lo, x_hi);
    
       printf (&quot;using %s method\n&quot;, 
               gsl_root_fsolver_name (s));
    
       printf (&quot;%5s [%9s, %9s] %9s %10s %9s\n&quot;,
               &quot;iter&quot;, &quot;lower&quot;, &quot;upper&quot;, &quot;root&quot;, 
               &quot;err&quot;, &quot;err(est)&quot;);
    
       do
         {
           iter++;
           status = gsl_root_fsolver_iterate (s);
           r = gsl_root_fsolver_root (s);
           x_lo = gsl_root_fsolver_x_lower (s);
           x_hi = gsl_root_fsolver_x_upper (s);
           status = gsl_root_test_interval (x_lo, x_hi,
                                            0, 0.001);
    
           if (status == GSL_SUCCESS)
             printf (&quot;Converged:\n&quot;);
    
           printf (&quot;%5d [%.7f, %.7f] %.7f %+.7f %.7f\n&quot;,
                   iter, x_lo, x_hi,
                   r, r - r_expected, 
                   x_hi - x_lo);
         }
       while (status == GSL_CONTINUE &amp;&amp; iter &lt; max_iter);
       return status;
     }
    
     
    • Jerry S.

      Jerry S. - 2006-07-09

      I created a VC++ 2005 Express project for this using a debug gsl dll built using the same compiler (converted from VC7). I had no unresolved references.

      The function in question (finite) is part of the VC runtime library, not gsl. Could you perhaps be linking against a different CRT than the gsl library or dll? Did you generate the dll yourself using VC8?

      If you're still having problems, please continue the dialog giving more details of the gsl library and VC configuration you're using.

      Thanks,
      Jerry

       
MongoDB Logo MongoDB