lanl / LaGriT

Los Alamos Grid Toolbox (LaGriT) is a library of user callable tools that provide mesh generation, mesh optimization and dynamic mesh maintenance in two and three dimensions.
https://lanl.github.io/LaGriT/
Other
116 stars 48 forks source link

`make static` on macOS does not compile a true static binary #208

Open daniellivingston opened 3 years ago

daniellivingston commented 3 years ago

Compiling with make static leaves libquadmath still dynamically linked:

$ make static
$ otool -L lagrit
lagrit:
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1252.250.1)
        /usr/local/opt/gcc/lib/gcc/10/libquadmath.0.dylib (compatibility version 1.0.0, current version 1.0.0)

This is a problem for binary portability.


On macOS, static linking is really hard:

It appears that the Mac OS X linker is hard-wired to search dynamic libraries before static ones...Note that you cannot pass a file extension to the -l switch (-lantlr3c.a) to force the static library to be used. One way to force the static library to be used is to simply remove the dynamic version.

A way I have compiled static libraries in the past is to do something like:

$ sudo mv /usr/local/opt/gcc/lib/gcc/10/libquadmath.0.dylib \
          /usr/local/opt/gcc/lib/gcc/10/tmp_libquadmath.0.dylib
$ make static
$ sudo mv /usr/local/opt/gcc/lib/gcc/10/tmp_libquadmath.0.dylib \
          /usr/local/opt/gcc/lib/gcc/10/libquadmath.0.dylib

That works but is not a good general solution. Currently trying to solve this in the branch mac-os-fix. https://github.com/lanl/LaGriT/tree/macos-static-fix

daniellivingston commented 3 years ago

Other references:

(0): https://stackoverflow.com/a/44728442/5150303 (1): https://stackoverflow.com/questions/844819/how-to-static-link-on-os-x (2): http://mad.web.cern.ch/mad/releases/madng/madng-git/src/Makefile.windows

Neither solution in 0 or 1 works.