user4468022
user4468022

Reputation:

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?

Upvotes: 4

Views: 5888

Answers (1)

Chol Nhial
Chol Nhial

Reputation: 1397

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`

Upvotes: 10

Related Questions