[Ur] Static compilation on Mac OSX - can't be done, so fall back to next best

Daniel Patterson dbp at dbpmail.net
Wed Jun 26 00:12:50 EDT 2013


Apparently Mac OSX prevents static compilation from working by not
providing static versions of basic libraries. This is active policy [1].

The next best approximation is to link in what we can provide
statically, and still have a dynamically linked binary, but hopefully
one with minimal dependencies. An easy approximation to this is to take
the exact command-line invocation that is currently generated with
-static, and remove the -static keyword to gcc. The binary produced by
this will not be dynamically linked against liburweb or liburweb_http,
but still will be against ssl, crypto, sqlite3, and libSystem. However,
at least on the system I'm experimenting on (10.7 - with some libraries,
perhaps these, installed through homebrew), all of those but libSystem
exist as static libraries, and by replacing -lssl (and company) by paths
to libssl.a (and company), I get a binary that looks like this:

$ otool -L app.exe
app.exe:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version
159.1.0)

Which I think could be considered optimal for the system. I'm not sure
how exactly this should be done - I don't know gcc (or mac osx) well
enough to know how to get it to track down all the static libraries that
it can while not failing if there are some it cannot. But, I think this
would be a better way of doing "static linking" on this system that is
hostile to it.

Thoughts? Is this an easy fix?

1. http://developer.apple.com/library/mac/#qa/qa1118/_index.html



More information about the Ur mailing list