Why can’t ld find this library

compilinglibrarieslinkermakestatic-linking

I'm not very knowledgeable on this topic, and therefore can't figure out why the following command does not work:

 $ gfortran -o dsimpletest -O  dsimpletest.o ../lib/libdmumps.a \ 
 ../lib/libmumps_common.a  -L/usr -lparmetis -lmetis -L../PORD/lib/ \
 -lpord -L/home/eiser/src/scotch_5.1.12_esmumps/lib -lptesmumps -lptscotch \
 -lptscotcherr /opt/scalapack/lib/libscalapack.a   -L/usr/lib/openmpi/ \ 
 -lmpi -L/opt/scalapack/lib/librefblas.a -lrefblas -lpthread
 /usr/bin/ld: cannot find -lrefblas
 collect2: ld returned 1 exit status

This happens when compiling the mumps library. The above command is executed by make. I've got the librefblas.a in the correct path:

$ ls /opt/scalapack/lib/ -l
total 20728
-rw-r--r-- 1 root root   619584 May  3 14:56 librefblas.a
-rw-r--r-- 1 root root  9828686 May  3 14:59 libreflapack.a
-rw-r--r-- 1 root root 10113810 May  3 15:06 libscalapack.a
-rw-r--r-- 1 root root   653924 May  3 14:59 libtmg.a

Question 1: I thought the -L switch of ld takes directories, why does it refer to the file directly here? If I remove the librefblas.a from the -L argument, I get a lot of "undefined reference" errors.

Question 2: -l should imply looking for .a and then looking for .so, if I recall correctly. Is it a problem that I don't have the .so file? I tried to find out by using gfortran -v ..., but this didn't help me debugging it.

Best Answer

I was able to solve this with the help of the comments, particular credit to @Mat.

Since I wanted to compile the openmpi version, it helped to use mpif90 instead of gfortran, which, on my system, is

 $ mpif90 --showme
 /usr/bin/gfortran -I/usr/include -pthread -I/usr/lib/openmpi -L/usr/lib/openmpi -lmpi_f90 -lmpi_f77 -lmpi -ldl -lhwloc
Related Question