[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-gsl] Gsl ODE sample program compiling erro.
From: |
Ming Lu |
Subject: |
[Help-gsl] Gsl ODE sample program compiling erro. |
Date: |
Thu, 10 Jul 2014 09:55:53 +0800 |
Dear All:
I am trying to compiling a sample program from gsl official website.
Here is the program LINK
<https://www.gnu.org/software/gsl/manual/html_node/ODE-Example-programs.html#ODE-Example-programs>,
I will also paste it below:
****************************************************************************************************
#include <stdio.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_odeiv2.h>
int func (double t, const double y[], double f[], void *params)
{
double mu = *(double *)params; //purpose?
f[0] = y[1];
f[1] = -y[0] - mu*y[1]*(y[0]*y[0] - 1);
return GSL_SUCCESS;
}
int jac (double t, const double y[], double *dfdy, double dfdt[], void
*params)
{
double mu = *(double *)params;
gsl_matrix_view dfdy_mat = gsl_matrix_view_array (dfdy, 2, 2);
gsl_matrix * m = &dfdy_mat.matrix;
gsl_matrix_set (m, 0, 0, 0.0);
gsl_matrix_set (m, 0, 1, 1.0);
gsl_matrix_set (m, 1, 0, -2.0*mu*y[0]*y[1] - 1.0);
gsl_matrix_set (m, 1, 1, -mu*(y[0]*y[0] - 1.0));
dfdt[0] = 0.0;
dfdt[1] = 0.0;
return GSL_SUCCESS;
}
int main (void)
{
double mu = 10;
gsl_odeiv2_system sys = {func, jac, 2, &mu};
gsl_odeiv2_driver * d = gsl_odeiv2_driver_alloc_y_new (&sys,
gsl_odeiv2_step_rk8pd,1e-6, 1e-6, 0.0);
int i;
double t = 0.0, t1 = 100.0;
double y[2] = { 1.0, 0.0 };
for (i = 1; i <= 100; i++)
{
double ti = i * t1 / 100.0;
int status = gsl_odeiv2_driver_apply (d, &t, ti, y);
if (status != GSL_SUCCESS)
{
printf ("error, return value=%d\n", status);
break;
}
printf ("%.5e %.5e %.5e\n", t, y[0], y[1]);
}
gsl_odeiv2_driver_free (d);
return 0;
}
**************************************************************************************************
I have installed gsl in the default place. When I tried to compile it use *gcc
-Wall example.c -c* , I have no
error shown. However when I use* gcc example.o* I got the errors:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ode_exp.o: In function `jac':
ode_exp.c:(.text+0xd1): undefined reference to `gsl_matrix_view_array'
ode_exp.c:(.text+0xf3): undefined reference to `gsl_matrix_set'
ode_exp.c:(.text+0x111): undefined reference to `gsl_matrix_set'
ode_exp.c:(.text+0x160): undefined reference to `gsl_matrix_set'
ode_exp.c:(.text+0x1ab): undefined reference to `gsl_matrix_set'
ode_exp.o: In function `main':
ode_exp.c:(.text+0x20b): undefined reference to `gsl_odeiv2_step_rk8pd'
ode_exp.c:(.text+0x22e): undefined reference to
`gsl_odeiv2_driver_alloc_y_new'
ode_exp.c:(.text+0x2a0): undefined reference to `gsl_odeiv2_driver_apply'
ode_exp.c:(.text+0x2fd): undefined reference to `gsl_odeiv2_driver_free'
collect2: ld returned 1 exit status
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Then I search the website and found actually someone have asked in this
maillist before about the
exactly the same problem. HERE IS THE LINK
<http://lists.gnu.org/archive/html/help-gsl/2012-05/msg00000.html> to that
question. I've tried the suggestion given by
the repliers.
That is: when I use: *gcc -o example exmaple.c -lgsl -lgslcblas -lm*
I got the error message:
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
/tmp/ccCF5OM2.o: In function `main':
ode_exp.c:(.text+0x20b): undefined reference to `gsl_odeiv2_step_rk8pd'
ode_exp.c:(.text+0x22e): undefined reference to
`gsl_odeiv2_driver_alloc_y_new'
ode_exp.c:(.text+0x2a0): undefined reference to `gsl_odeiv2_driver_apply'
ode_exp.c:(.text+0x2fd): undefined reference to `gsl_odeiv2_driver_free'
collect2: ld returned 1 exit status
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Can someone help me? If you need more information, please let me know.
--
Regards,
Ming Lu
----
Ming Lu, graduate student of second year,
ICQM, Peking University <http://icqm.pku.edu.cn>
- [Help-gsl] Gsl ODE sample program compiling erro.,
Ming Lu <=