5

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.

Sebastian
  • 8,677
  • 4
  • 39
  • 49
  • Are you sure `gfortran` searches that path? I don't know gfortran, but I'd first check `set | grep PATH` for anything looking useful. – jippie May 04 '12 at 07:06
  • `set | grep scala` returns nothing. how can I add this path? – Sebastian May 04 '12 at 07:20
  • I think your instinct to make the last `-L` a directory was correct. What symbols were undefined when you did that? – ckhan May 04 '12 at 07:22
  • 2
    If you get undefined references but no more "cannot find -lfoo", it means it found your libraries. But you're missing other libraries and/or got your link order wrong. Without seeing _what_ undefined references you have, this question is unanswerable. – Mat May 04 '12 at 07:26
  • http://pastebin.com/SCx1Vz5b shows the output when omitting the `librefblas.a` from the `-L` option. It's fishy that all these errors are related to mpi.... @Mat, thanks for this hint! I've got, `/usr/lib/openmpi/libmpi.so` available. – Sebastian May 04 '12 at 07:29
  • 1
    Try reordering the libraries, linking to refblas and then to mpi... I've no clue why but once it solved my problem when linking with gcc/ld! – Huygens May 04 '12 at 11:28

1 Answers1

2

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
Sebastian
  • 8,677
  • 4
  • 39
  • 49