Skip to content

static linking of libgfortran fails #326

Closed
drjdn opened this Issue Jan 3, 2012 · 16 comments

6 participants

@drjdn
drjdn commented Jan 3, 2012

When building julia I get the following error when compiling LAPACK:

make[2]: Leaving directory /usr/local/julia/external/lapack-3.4.0'
cd lapack-3.4.0 && gfortran -shared -static-libgfortran SRC/*.o INSTALL/dlamch.o INSTALL/dsecnd_INT_ETIME.o INSTALL/ilaver.o INSTALL/slamch.o ../openblas-v0.1alpha2.4/libopenblas.a -o liblapack.so
/usr/bin/ld: /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/libgfortran.a(stop.o): relocation R_X86_64_32 against
.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC /usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/libgfortran.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make[1]: *** [lapack-3.4.0/liblapack.so] Error 1
make[1]: Leaving directory `/usr/local/julia/external'
make: *** [julia-release] Error 2

this seems to indicate that stop.c in the gfortran runtime was not compiled with -fPIC... I haven't rebuild julia's dependencies is several weeks so I'm not sure what could have caused this issue (same libgfortran.a that is the stock version that ships with Ubuntu that I used to build previously).

Jason

@JeffBezanson JeffBezanson reopened this Jan 3, 2012
@JeffBezanson
The Julia Language member

Oops I somehow hit a key that closed the issue.

Removing the -static-libgfortran flag might fix this. If so, we can make this an option for people who already have libgfortran installed.

@drjdn
drjdn commented Jan 3, 2012

I can confirm that removing -static-libgfortran results in a successful build. The pre-built libgfortran from Ubuntu's apt repo does include libgfortran.a so in theory the flag should work.

@StefanKarpinski
The Julia Language member

Ugh. Not having a statically linked libgfortran makes the binaries not work. Having a statically linked libgfortran makes the build process fail. Do we need to resort to downloading and compiling our own damned gfortran just so that we can reliably statically link against it?

@ViralBShah
The Julia Language member

I think it may have to do with the version of gfortran being used. We should enable the flag on Mac, since gfortran is not standard on the mac. On linux, it is trivial to get the libgfortran libraries through the package managers, if it is not already installed.

@ViralBShah
The Julia Language member

Oddly enough, -static-libgfortran works fine on Debian Squeeze.

@StefanKarpinski
The Julia Language member

When I was trying to get a few friends to try out Julia on linux VMs, they encountered the libgfortran linking problem, so it is an issue on some Linux systems also.

@ViralBShah
The Julia Language member

@drjdn - what version of Ubuntu are you using?

@StefanKarpinski
The Julia Language member

Maybe our binary installs should just include libgfortran from where it was compiled?

@drjdn
drjdn commented Jan 8, 2012
@ViralBShah
The Julia Language member

There are quite a few dependencies that gfortran uses, not just libgfortran. For example:

$ otool -L liblapack.dylib
liblapack.dylib:
libLAPACK.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/local/lib/libgfortran.3.dylib (compatibility version 4.0.0, current version 4.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
/usr/local/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/local/lib/libquadmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)

The tarballs created by the dist target won't work currently unless gfortran is installed on both, mac and linux. Revisiting the error posted by @drjdn, it may be that we just need to pass -fPIC in a few more places when building lapack.

@ViralBShah
The Julia Language member

I tried this out on ubuntu 11.10 and don't see the error. Everything seems to work fine. However, I am quite sure that libquadmath is going to be an issue, which does not get linked statically even when using -static-libgfortran.

See: http://gcc.gnu.org/ml/fortran/2010-11/msg00280.html

@ViralBShah
The Julia Language member

In order to get this right, we may just need to ship all the libgcc, libgfortran, libquadmath and whatever other compiler specific libraries are needed, and then load julia through a shell script that sets the right LD_LIBRARY_PATH.

@StefanKarpinski
The Julia Language member

We don't need a script, we can set the environment variable in C/Julia code before loading any libraries.

@ViralBShah
The Julia Language member

I am closing this issue because there is really no way to link libgfortran statically, due to the libquadmath dependency. We will ship libgfortran and libquadmath in our standalone binary distributions.

@ViralBShah ViralBShah closed this May 2, 2012
@chriswadeCity

how do i remove static link to -static-libgfortran

@tkelman
The Julia Language member
tkelman commented Mar 3, 2016

This is possible by replacing -lgfortran with absolute paths to libgfortran.a and libquadmath.a, but if you want to statically link libgfortran into a shared library of blas or whatever, you need libgfortran itself to be built --with-pic. No Linux distributions that I know of distribute a copy of libgfortran that is built that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.