3

i have been trying for hours and it drives me crazy. The last error I get is :

demo_cblas.c:(.text+0x83): undefined reference to `clapack_sgetrf'
demo_cblas.c:(.text+0xa3): undefined reference to `clapack_sgetri'

I am compiling the code using

/usr/bin/gcc -o demo_cblas demo_cblas.c -L /usr/lib64 -l :libgfortran.so.3 -L /usr/lib64 \
    -llapack -L /usr/lib64 -lblas 

I try with and without libgfortran, with different compilers gcc-33, gcc-47, gcc-48. The test code is not from me but comes from this forum ...

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include "clapack.h"
#include "cblas.h"

void invertMatrix(float *a, unsigned int height){
int info, ipiv[height];
info = clapack_sgetrf(CblasColMajor, height, height, a, height, ipiv);
info = clapack_sgetri(CblasColMajor, height, a, height, ipiv);
}

void displayMatrix(float *a, unsigned int height, unsigned int width)
{
int i, j;
for(i = 0; i < height; i++){
for(j = 0; j < width; j++)
{
                printf("%1.3f ", a[height*j + i]);
        }
        printf("\n");
}
printf("\n");
}


int main(int argc, char *argv[])
{
int i;
float a[9], b[9], c[9];
srand(time(NULL));
for(i = 0; i < 9; i++)
{
        a[i] = 1.0f*rand()/RAND_MAX;
        b[i] = a[i];
}
displayMatrix(a, 3, 3);
return 0;
}

I am on Suse 12.3 64bits. In /usr/lib64 I have liblapack.a liblapack.so, ... and libblas.a libblas.so, ... and libgfortran.so.3

The same code without the function "invertMatrix" (the one using the library) compiles fine.

Any idea or suggestion ?

Thank you all for your help.

Vava

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • What is `:libgfortran.so.3`? Why not just `gfortran`? – John Zwinck Jun 26 '14 at 10:14
  • in /usr/lib64 is only libgfortran.so.3 and no libgfortran.a or libgfortran.so. I do not why it is so ? I have also read that lapack needs this lib, but it does not seem to change anything in this particular case. – user3778776 Jun 26 '14 at 11:24
  • It sounds like you're missing some sort of "dev" package for libgfortran--usually that's what would install a symlink from /usr/lib64/libgfortran.so -> libgfortran.so.3. The "3" file would usually come from a "runtime" package and if you don't have the symlink to it, you're missing a "dev" package somewhere. – John Zwinck Jun 26 '14 at 13:17

2 Answers2

2

I'm quite positive that you also need to link to libcblas, which is the c wrapper library for libblas. Note that libblas is a FORTRAN library which therefore does not contain the function clapack_* you're calling.

downhillFromHere
  • 1,967
  • 11
  • 11
  • I try with libclas but to no avail. Regarding clapack_* it is defined in the header clapack.h. In this post http://stackoverflow.com/questions/6567849/lapacke-or-clapack-if-programming-in-c-c-in-linux – user3778776 Jun 26 '14 at 13:03
  • it is said clapack can be compiled with a c compiler using some "f2c converter" (which i have installed by the way). I understand I do not have to care for this "conversion". I am confused ... – user3778776 Jun 26 '14 at 13:11
  • If you're working on windows, you might want to try this: http://hep.ph.liv.ac.uk/~hock/My_reports/CLAPACK/CLAPACK%20INSTALLING,%20USING.htm .On Linux, it's much easier to use cblas that comes with GNU scientific library (GSL). Even easier, you could call the fortran function directly without going through clapack wrapper, since you already have liblapack and libblas installed. – downhillFromHere Jun 26 '14 at 13:32
0

I've just got this working on FreeBSD with:

gcc -o test test.c  \
-llapack -lblas -lalapack -lcblas

I'd installed math/atlas (from ports) and the lapack and blas packages.

See my question here

Community
  • 1
  • 1
Ivan Uemlianin
  • 953
  • 7
  • 21