0

As I discussed in a previous question, I am trying to run a python script that uses f2py wrapped Fortran code on a remote server. If I compile the f2py module locally on my own pc and then run the script on the server, I get the following error,

ImportError: liblapack.so.3: cannot open shared object file: No such file or directory

This is logical since lapack and blas are both not installed on the remote server, and sadly I do not have the root privileges to install them. I am wondering if I could fix this by using static linking. On the GNU wiki it is stated that,

One way to avoid this (more ideas can be found on the binaries page) is to use the so-called "static linking", available with option -static. Gfortran then puts the library code inside the program created, thus enabling it to run without the library present (like, on a computer where gfortran is not installed).

This sounds like exactly what I would need. If the required library files are included in the f2py module then I won't need the lapack and blas modules on the remote server and I can just run it as is. However I am not sure that this static linking actually works with f2py. Currently I run,

python -m numpy.f2py -llapack -lblas -c --fcompiler=gnu95 --compiler=unix signature_file.pyf 
object_files.o

object_files.o means all interdependent Fortran files compiled into object files, i.e. I ran

gfortran -c -llapack -lblas object_file.F90 

on all relevant files. Now I would like to do this with static linking, but how? I have tried adding -static when compiling the object files, but this didn't change anything. I have also tried adding -static to the f2py call, but this just gives an unknown option error.

Jasper
  • 87
  • 7
  • *and sadly I do not have the root privileges to install them*: Not a problem, install the DLLs in a directory that you add to the `LD_LIBRARY_PATH` environment variable. Regarding the static linking, it should be possible, but note that f2py builds a dynamic library anyway. However, I believe you can link a static version of blas/lapack to build this dll (maybe by forcing the correct `liblapack.a` file instead of just `-llapack`? -- if the static libs are installed on your local machine, by the way) –  Dec 22 '20 at 16:52
  • Can't you just copy liblapack.so.3 and any dependencies to the remote server, set the LD_LIBRARY_PATH to where you've copied it and run? Use ldd on liblapack.so.3 to find out what else it is picking up. – cup Dec 23 '20 at 07:35

1 Answers1

0

Yes, this is possible inside a setup.py script if you use Extension from numpy.distutils.core with extra_link_args=["-static", "-static-libgfortran", "-static-libgcc"].

It is explained in this answer.

Amos Egel
  • 937
  • 10
  • 24