"undefined reference to `dgesvx_'" although LAPACK is installed and located

135 Views Asked by At

I'm trying to run a fortran script that includes the function dgesvx(). I ran the script as gfortran -lblas -llapack -o cft numtype.o cfapprox.o cftest.o

and the output is

gfortran -lblas -llapack -o cft numtype.o cfapprox.o cftest.o /usr/bin/ld: cfapprox.o: in function __taylor_cf_approx_MOD_pade_coef': cfapprox.f90:(.text+0x3c4): undefined reference to dgesvx_' collect2: error: ld returned 1 exit status make: *** [Makefile:18: cft] Error 1

I'm running Ubuntu on WSL.

I installed multiple libraries that have blas and lapack and when I compile It locates the lapack library.

1

There are 1 best solutions below

0
Ian Bush On

Amazingly I can't quickly find a duplicate to this. But the answer is hidden in the comments to Lapack undefined reference Quoting from there "If you're linking static libs the linker will drop any names that haven't been referenced in the chain up to that point" and "by default, the GNU linker only does a single pass over the libraries in order. You can request multiple passes with --start-group". Putting this together

gfortran cfapprox.o cftest.o -o cft -llapack -lblas

Solves this particularly case, and as a general rule of thumb put all libraries you want to link against at the end of the link line.

While I am here note the lapack and blas libraries that come with most Linuces are not optimised - you will probably get better performance if you install and link against openblas instead - see here for installation on Ubuntu. You can then simply link against -lopenblas. Intel's mkl is another optimised alternative.