This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

static linking of libgfortran


Hi all,

I'm the author of https://github.com/fommil/netlib-java and I'm using gcc (and mingw) cross-compilers to build fortran JNI (java native interface) libraries on all major platforms.

One of the constraints of the way these JNI libs are packaged is that they must be shipped as a single self-contained library file.

On OS X (using macport's gcc) I am able to build a shared library for OS X, with the libgfortran statically included using the following linker flags:

-dynamiclib -static-libgfortran /opt/local/lib/gcc48/libquadmath.a
-static-libgcc -lgfortran

(note that there is no "-static-libquadmath" so the static archive sadly must be referenced explicitly).


Using MinGW, I am able to include the fortran libs (although I'm not 100% sure if this is safe at runtime... what about libgcc / libquadmath?)

-shared /usr/lib/gcc/x86_64-w64-mingw32/4.6/libgfortran.a


However, on Linux (natively x86_64, i686 and cross compiled for gnueabihf) I am unable to build a shared library that includes the fortran library. This results in dynamic references to the libgfortan (obviously the static reference is silently ignored)

-shared -static-libgfortran -lgfortran

and an attempt to reference the libgfortran.a explicitly results in something like:

/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/../../../../arm-linux-gnueabihf/bin/ld: /usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/libgfortran.a(stop.o): relocation R_ARM_THM_MOVW_ABS_NC against `a local symbol' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc-cross/arm-linux-gnueabihf/4.7/libgfortran.a: could not read symbols: Bad value
collect2: error: ld returned 1 exit status


It would seem like the Ubuntu distribution of gcc is building the fortran library without -fPIC making it impossible to include in a shared library.

Are Ubuntu building the libgfortran.a correctly?

Can anyone suggest a workaround that would allow me to build the binary the way I want (and alleviate the requirement that libgfortran be installed on the target machine)? I'd be happy building a static library instead of a .so but I don't want to include the kitchen sink (i.e. libc and libm)!


[I'm meeting a practical requirement. I am aware that the availability of the libgfortran routines at runtime is the responsibility of the system's package-manager. However, it is not possible to distribute additional shared libraries due to the way that we're loading JNI, and end-users do not have root privileges to be able to install the shared fortran library]


-- 
Sam


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]