easybuild-easyblocks icon indicating copy to clipboard operation
easybuild-easyblocks copied to clipboard

GCC not built with PIC - static linking fails

Open DirkdeDraak opened this issue 9 years ago • 2 comments

Today one of our developers wanted/needed to statically link to libgfortran. Though that fails. Reason is that GCC is not configured with --with-pic. I can of course add "configopts = '--with-pic'" to all GCC-.eb and GCCcore-.eb files, or better to the gcc easyblock. May I suggest to add --with-pic to gcc.py by default?

Example to test if it is working:

gfortran -c -fPIC test.f90
gfortran -static-libgfortran -shared -o libtest.so test.o

>>>>>>>>>>>> CODE for test.f90 <<<<<<<<<<
 subroutine subber
 print*,'hi'
 end
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

DirkdeDraak avatar Feb 25 '16 10:02 DirkdeDraak

@DirkdeDraak: please share the exact error messages you were running into?

I remember running into similar problems a while ago, and building GCC with PIC enabled sounds easier than it is...

See also https://github.com/JuliaLang/julia/issues/326, where they conclude fully statically linking to libgfortran doesn't work (although that may not be what you're after).

boegel avatar Feb 27 '16 12:02 boegel

Just to make this issue a bit easier to find: when statically linking -lgfortran, you'll hit an error like:

/software/binutils/2.31.1/bin/ld.gold: error: /software/GCCcore/8.2.0/lib/gcc/x86_64-pc-linux-gnu/8.2.0/../../../../lib64/libgfortran.a(fpu.o): requires unsupported dynamic reloc 11; recompile with -fPIC

boegel avatar Nov 17 '21 20:11 boegel