Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static -libgfortran in library build

I am trying to build a library that only has static references to libgfortran (and preferably libgcc also).

However, if I use the linker flags

-static -lgfortran -static-libgfortran -static-libgcc

on OS X I get

ld: library not found for -lcrt0.o
collect2: error: ld returned 1 exit status

and if I try to use

-shared -lgfortran -static-libgfortran

I get

Undefined symbols for architecture x86_64:
  "_quadmath_snprintf", referenced from:
      _write_float in libgfortran.a(write.o)
  "_strtoflt128", referenced from:
      __gfortrani_convert_real in libgfortran.a(read.o)
      __gfortrani_convert_infnan in libgfortran.a(read.o)

and everything compiles fine (but has a dynamic link to libgfortran and libgcc) if I use -dynamiclib -lgfortran.

It would appear that gcc is not build statically on OS X.

How do I build my library so that end-users don't need to have gfortran or gcc installed?

I'm using the macports version of gcc but I'm prepared to use another distributor of gfortran/gcc if it allows me to do this.

like image 862
fommil Avatar asked Jul 28 '13 17:07

fommil


1 Answers

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

seems to do the trick!

The bizarre thing was figuring out that I needed to add a full path to the libquadmath.a, which feels like a bug with gcc/gfortran to be honest.

like image 127
fommil Avatar answered Sep 23 '22 22:09

fommil