0

I have problems running the cblas parts of the gsl (gnu scientific library).

The example below (from the gsl manual) compiles a links perfectly but, gives an error when running. This is under Ubuntu 12.04.

gcc linsys.c -lgsl -lcblas -lm

./a.out: symbol lookup error: /usr/lib/libgsl.so.0: undefined symbol: cblas_dtrsv

 #include <stdio.h>
 #include <gsl/gsl_linalg.h>
 
 int
 main (void)
 {
   double a_data[] = { 0.18, 0.60, 0.57, 0.96,
                       0.41, 0.24, 0.99, 0.58,
                       0.14, 0.30, 0.97, 0.66,
                       0.51, 0.13, 0.19, 0.85 };
 
   double b_data[] = { 1.0, 2.0, 3.0, 4.0 };
 
   gsl_matrix_view m 
     = gsl_matrix_view_array (a_data, 4, 4);
 
   gsl_vector_view b
     = gsl_vector_view_array (b_data, 4);
 
   gsl_vector *x = gsl_vector_alloc (4);
   
   int s;
 
   gsl_permutation * p = gsl_permutation_alloc (4);
 
   gsl_linalg_LU_decomp (&m.matrix, p, &s);
 
   gsl_linalg_LU_solve (&m.matrix, p, &b.vector, x);
 
   printf ("x = \n");
   gsl_vector_fprintf (stdout, x, "%g");
 
   gsl_permutation_free (p);
   gsl_vector_free (x);
   return 0;
 }
Community
  • 1
  • 1
Floyd
  • 739
  • 1
  • 7
  • 20

2 Answers2

1

On my ubuntu system, the library name is gslcblas and full path is /usr/lib/libgslcblas.so. I tried your code with this library and it compiles with:

gcc gl.c -lgsl -lgslcblas -lm

Can you check if you have this library and compile with it? If not, you can also install it:

sudo apt-get install libgsl0-dev


Libraries linked and output:

$ ldd a.out 
    linux-gate.so.1 =>  (0xb771d000)
    libgsl.so.0 => /usr/lib/libgsl.so.0 (0xb74e5000)
    libgslcblas.so.0 => /usr/lib/libgslcblas.so.0 (0xb74a7000)
    libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xb72fc000)
    libm.so.6 => /lib/i386-linux-gnu/libm.so.6 (0xb72d0000)
    /lib/ld-linux.so.2 (0xb771e000)

$ ./a.out 
x = 
-4.05205
-12.6056
1.66091
8.69377
$ 
P.P
  • 117,907
  • 20
  • 175
  • 238
  • I have tried that too. The links succeed, but when i RUN it, I get undefined symbol: cblas_dtrsv. What is your result when running the linked test program. Really, I would prefer to just have a static link, instead of the dynamic library hell. – Floyd Jan 19 '13 at 05:26
  • I added the output of the program and `ldd`. – P.P Jan 19 '13 at 10:58
  • Thanks! It was a problem with the binutils gold linker which somehow crept into my system... – Floyd Jan 19 '13 at 11:58
1

@KingsIndian. Thanks a bunch for your output, which helped me track down and solve that annoying problem.

Solution: 'apt-get remove binutils-gold' and recompile/link.

Reason: ld.gold does not add the libgslcblas, while the standard linke does it.

ldd output of my executable:

> ldd a.out 
> linux-vdso.so.1 =>  (0x00007fffb67ff000)
> libgsl.so.0 => /usr/lib/libgsl.so.0 (0x00007f0819468000)
> libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f08190a9000)
> libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f0818dac000)
> /lib64/ld-linux-x86-64.so.2 (0x00007f08198cd000)

We see the glaring omission of libgslcblas! I copied my code to another ubuntu system (which is running 12.04.1 lts as well and compiled it. Lo and behold, the same program runs after compiling with the same compiler switches!

  • Comparing the versions of gcc showed that they are exactly the same on both systems (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)).
  • The installed gsl.so files are identical as well, which is expected with two updated systems of the same version.

Perhaps the linkers are different?

On my 'problem system':

ld -v GNU gold (GNU Binutils for Ubuntu 2.22) 1.11

On the 'good system':

ld -v GNU ld (GNU Binutils for Ubuntu) 2.22

Removing binutils gold and recompiling the test program, and .. success!

Bottom line: Linker problem, solved.

Floyd
  • 739
  • 1
  • 7
  • 20