Building shared libraries with fortran

Here’s another question…thanks for the help preemptively.

I have been trying to package a python package that wraps an underlying Fortran code. This python package is built using cython’s distutils package, which needs to build a shared library. The build fails on the linking step, complaining about libgfortran not being compiled with -fPIC.

 /nix/store/md4zqxlmza5d7xxb13ajyvifbjrj38sg-gfortran-9.3.0/lib/libgfortran.a(maxloc0_4_i4.o): relocation R_X86_64_32 against `.rodata._gfortran_maxloc0_4_i4.str1.1' can not be used when making a shared object; recompile with -fPIC

I tried many combinations of linkers and flags, but could not get anything to work. The problem seems that the gfortran included in nixpkgs 1) only includes a static libgfortran which is 2) not compiled with -fPIC. I found a related bug report on GCC from a long time ago.

Is it really the case that I cannot construct a shared library from the gfortran in nixpkgs or do I have some bug in my build? I could try to build a minimal example if it helps.

1 Like

This looks relevant: Shared libgfortran missing from gfortran.cc.lib

Yah. that solved my problem… need to use gfortran.cc.lib to get link against the dynamic lib rather than the static one.