Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined references in GSL

I'm trying to link gsl in a small c program.

#include "stdlib.h"
#include "stdio.h"
#include "gsl/gsl_block_float.h"
#include "gsl/gsl_matrix_float.h"

int main(void)
{
  gsl_matrix_float* m = gsl_matrix_float_alloc(2, 2);
  gsl_matrix_float_fprintf(stdout, m, "%f");
}

I'm compiling with gcc -lgsl -lgslcblas -lm program.c. I've tried gcc $(pkg-config --cflags gsl) $(pkg-config --libs gsl) program.c as well, along with gsl-config. In every case, gcc returns

/tmp/cc1wKgXm.o: In function `main':
program.c:(.text+0x13): undefined reference to `gsl_matrix_float_alloc'
program.c:(.text+0x32): undefined reference to `gsl_matrix_float_fprintf'
collect2: error: ld returned 1 exit status

objdump --syms /usr/lib/libgsl.so | grep gsl_matrix_float returns the proper symbols, as does grepping my headers. Everything is in /usr/lib or /usr/include What am I doing wrong?


1 Answers

I got this from the ubuntu forums. The order of the arguments togcc might be the issue

gcc -o program program.c `gsl-config --cflags --libs`
like image 89
Chol Nhial Avatar answered Nov 01 '25 06:11

Chol Nhial



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!