Julius Plenz – Blog

Today, virtually all binaries used on linux systems are dynamically
linked to several libraries. While it is commonly accepted statically
linking applications is bad – most notably in terms of
security concerns: fixing a library's bug means you won't have to
recompile all applications that are using that special library,
they'll simply load the version available at run-time – there
are in fact good reasons to use static linking. (And for those who
claim statically linked binaries occupy much disk space: yeah, sure.
As if a few megs compared to a few hundred kilobytes make that much a
difference today, plus you don't have the overhead of looking up and
loading the libs in the first place.)

As I mentioned in my post about tmux already, there's a
huge advantage to static linking: you can compile bleeding edge
software with bleeding edge library functions and still use them on
reasonably outdated systems (think: Debian stable).

One division of rapidly evolving software I could never successfully link
statically was window managers like dwm or awesome.
However, especially considering the XCB development and adoption over
the past few years, to me it makes perfect sense. I'll just distribute
a copy of the window manager I use to different systems and have a
guarantee it'll work there, no matter the libxcb version (or if it's
available at all).

Usually, however, it's not possible to just pass a -static or
-Wl,-Bstatic flag to the compiler (in my case, gcc). It'll fail to
find several symbols that are located in libraries that don't have to
be explicitly linked in. Such an error message might look like this:

There's one important point here: libX11 will (to me, it seems,
inevitably) load another library, not sure why or which one. Thus, it
is vitally important to statically link in libdl, the library that
dynamically loads another library. Otherwise, the follwing error
messages appear:

You can reduce the binary's size by a few hundred kilobytes by
manually calling strip(1).

The binary works very well for me. I'll try to use it on different
systems over the next few weeks and see what happens. If that works
out well, I'll also try to get lucky with awesome and zathura, as
these (and the libraries needed) are not installed on many systems,
either.