7

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.

Community
  • 1
  • 1
fommil
  • 5,757
  • 8
  • 41
  • 81

1 Answers1

11
-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.

fommil
  • 5,757
  • 8
  • 41
  • 81
  • 1
    Based on your solution, i ended up with this one: `-l:libgfortran.a -l:libquadmath.a` . I did not need static libgcc so did not try that part. – fchen Mar 12 '19 at 03:12