Static Linking

Jonathan Nieder
Tue Feb 22 19:18:00 GMT 2011


Julius Schmidt wrote:

> Some functions in glibc like gethostbyaddr don't like to be
> statically linked (well, you can, but they require the dynamic
> libraries, defeating the purpose of static linking)

If I had to guess, this change was introduced in cvs/glibc-2_3_3~505
(nis/nss_compat/compat-*.c: Don't use our own NIS/NIS+ functions,
dlopen corresponding NSS module instead, 2003-06-26).  Searching
libc-alpha yields [1] which suggests it was used to make the
nameservice switch _extensible_: that is, /etc/nsswitch.conf can
request use of an NSS module that didn't even exist when glibc was

And that is just good software engineering practice.


> (beyond hurr durr static linking sucks why do
> you use it; i know, Ulrich)

Now that is a separate question.  I believe you can get most of
the benefits of static linking by linking statically to everything
_except_ libraries like libc; libc has a very stable ABI so linking
dynamically to it is just as good (better, actually) if you are
careful about not linking to too-new symbols.

See also "2.22. Even statically linked programs need some shared
libraries" in the glibc FAQ.

Hope that helps,

More information about the Libc-help mailing list