Eu tenho um problema com a biblioteca gsl em Oneiric - depois de atualizar de Natty para Oneiric eu não posso mais construir um programa com meu próprio makefile, apesar do fato de que no QT Creator tudo funciona bem e o programa compila sem problemas. Os flags necessários para as bibliotecas gsl são definidos em ambos os makefiles e no Natty ambas as formas de compilar o programa funcionaram bem. Os arquivos da biblioteca gsl estão todos instalados.
EDIT: o código original que eu tentei compilar é escrito em c ++, que é a razão que eu uso o g ++ também com o arquivo test.c
Esta é a mensagem de erro:
user@user:~$ g++ -lgsl -lgslcblas -lm /home/user/test.c
/home/user/test.c: In function ‘int main()’:
/home/user/test.c:92:24: warning: format ‘%d’ expects argument of type ‘int’, but
argument 2 has type ‘size_t {aka long unsigned int}’ [-Wformat]
/tmp/ccOLKTZH.o: In function 'my_f(gsl_vector const*, void*)':
test.c:(.text+0x25): undefined reference to 'gsl_vector_get'
test.c:(.text+0x3b): undefined reference to 'gsl_vector_get'
/tmp/ccOLKTZH.o: In function 'my_df(gsl_vector const*, void*, gsl_vector*)':
test.c:(.text+0xf7): undefined reference to 'gsl_vector_get'
test.c:(.text+0x10d): undefined reference to 'gsl_vector_get'
test.c:(.text+0x14c): undefined reference to 'gsl_vector_set'
test.c:(.text+0x18a): undefined reference to 'gsl_vector_set'
/tmp/ccOLKTZH.o: In function 'main':
test.c:(.text+0x26b): undefined reference to 'gsl_vector_alloc'
test.c:(.text+0x288): undefined reference to 'gsl_vector_set'
test.c:(.text+0x2a1): undefined reference to 'gsl_vector_set'
test.c:(.text+0x2a8): undefined reference to 'gsl_multimin_fdfminimizer_conjugate_fr'
test.c:(.text+0x2bd): undefined reference to 'gsl_multimin_fdfminimizer_alloc'
test.c:(.text+0x2e8): undefined reference to 'gsl_multimin_fdfminimizer_set'
test.c:(.text+0x2f9): undefined reference to 'gsl_multimin_fdfminimizer_iterate'
test.c:(.text+0x31e): undefined reference to 'gsl_multimin_test_gradient'
test.c:(.text+0x357): undefined reference to 'gsl_vector_get'
test.c:(.text+0x374): undefined reference to 'gsl_vector_get'
test.c:(.text+0x3ca): undefined reference to 'gsl_multimin_fdfminimizer_free'
test.c:(.text+0x3d6): undefined reference to 'gsl_vector_free'
collect2: ld returned 1 exit status
Este é o arquivo que usei para fins de teste:
#include <gsl/gsl_multimin.h>
/* Paraboloid centered on (p[0],p[1]), with
scale factors (p[2],p[3]) and minimum p[4] */
double
my_f (const gsl_vector *v, void *params)
{
double x, y;
double *p = (double *)params;
x = gsl_vector_get(v, 0);
y = gsl_vector_get(v, 1);
return p[2] * (x - p[0]) * (x - p[0]) +
p[3] * (y - p[1]) * (y - p[1]) + p[4];
}
/* The gradient of f, df = (df/dx, df/dy). */
void
my_df (const gsl_vector *v, void *params,
gsl_vector *df)
{
double x, y;
double *p = (double *)params;
x = gsl_vector_get(v, 0);
y = gsl_vector_get(v, 1);
gsl_vector_set(df, 0, 2.0 * p[2] * (x - p[0]));
gsl_vector_set(df, 1, 2.0 * p[3] * (y - p[1]));
}
/* Compute both f and df together. */
void
my_fdf (const gsl_vector *x, void *params,
double *f, gsl_vector *df)
{
*f = my_f(x, params);
my_df(x, params, df);
}
int
main (void)
{
size_t iter = 0;
int status;
const gsl_multimin_fdfminimizer_type *T;
gsl_multimin_fdfminimizer *s;
/* Position of the minimum (1,2), scale factors
10,20, height 30. */
double par[5] = { 1.0, 2.0, 10.0, 20.0, 30.0 };
gsl_vector *x;
gsl_multimin_function_fdf my_func;
my_func.n = 2;
my_func.f = my_f;
my_func.df = my_df;
my_func.fdf = my_fdf;
my_func.params = par;
/* Starting point, x = (5,7) */
x = gsl_vector_alloc (2);
gsl_vector_set (x, 0, 5.0);
gsl_vector_set (x, 1, 7.0);
T = gsl_multimin_fdfminimizer_conjugate_fr;
s = gsl_multimin_fdfminimizer_alloc (T, 2);
gsl_multimin_fdfminimizer_set (s, &my_func, x, 0.01, 1e-4);
do
{
iter++;
status = gsl_multimin_fdfminimizer_iterate (s);
if (status)
break;
status = gsl_multimin_test_gradient (s->gradient, 1e-3);
if (status == GSL_SUCCESS)
printf ("Minimum found at:\n");
printf ("%5d %.5f %.5f %10.5f\n", iter,
gsl_vector_get (s->x, 0),
gsl_vector_get (s->x, 1),
s->f);
}
while (status == GSL_CONTINUE && iter < 100);
gsl_multimin_fdfminimizer_free (s);
gsl_vector_free (x);
return 0;
}