Statically linked binary?
glynn.clements at virgin.net
Fri May 21 17:14:49 EDT 2004
Jochen L. Leidner wrote:
> sorry for an urgent newbie question: how can I create a statically
> compiled version of a Haskell program on Linux with GHC that does not rely
> on external shared libs (also for any of its libraries it uses)?
Possibly with a great deal of difficulty, depending upon which
functions you need to use.
GNU libc 2.x dynamically loads shared libraries (with dlopen()) for
various "database" lookups (passwd, group, hosts etc). This applies
even when using a static libc (libc.a).
If you need to call (directly or indirectly) any of the functions
which use this mechanism, then you have to either:
a) have (the correct versions of) the relevant libnss_*.so libraries
installed on the target system, or
b) you have to compile your own libc.a using the --enable-static-nss
The most common functions which require this mechanism are those which
access the passwd database (getpwnam, getpwuid, etc) and those which
perform hostname/domain lookups (gethostbyname etc). Even if you don't
use these functions directly from your program, the libraries which
you use might use them. E.g.:
+ X needs to resolve the hostname part of $DISPLAY, so anything
which uses X is affected.
+ Anything which supports the "~user" syntax to refer to a specific
user's home directory will need to use getpwnam().
+ Anything which needs to translate between UIDs and usernames will
need to use getpwnam() and/or getpwuid().
Glynn Clements <glynn.clements at virgin.net>
More information about the Glasgow-haskell-users