[Haskell-cafe] GHC and libc

Glynn Clements glynn.clements at virgin.net
Sun May 16 11:37:35 EDT 2004

Per Larsson wrote:

> P.S Now everything seems to work, except that I get the compiler message:
> /usr/local/lib/ghc-6.2/libHSunix.a(User__17.o)(.text+0x160): In function    
> 'SystemziPosixziUser_getUserEntryForName_entry':
> : Using 'getpwnam_r' in statically linked applications requires at runtime the 
> shared libraries from the glibc version used for linking
> This seems to indicate that there are a few functions (probably in the Posix 
> package) which can't be can't be statically linked?

This is due to glibc's "name service switch" (NSS) feature. In
essence, access to system databases (passwd, group, hosts etc) is
delegated at run time to a dynamically-loaded library (using dlopen). 
Depending upon the configuration settings in /etc/nsswitch.conf, the
data can be obtained from text files, Berkeley DB files, NIS/NIS+ etc.

The following entry is from the glibc FAQ:

: 2.22.	Even statically linked programs need some shared libraries
: 	which is not acceptable for me.  What can I do?
: {AJ} NSS (for details just type `info libc "Name Service Switch"') won't
: work properly without shared libraries.  NSS allows using different services
: (e.g. NIS, files, db, hesiod) by just changing one configuration file
: (/etc/nsswitch.conf) without relinking any programs.  The only disadvantage
: is that now static libraries need to access shared libraries.  This is
: handled transparently by the GNU C library.
: A solution is to configure glibc with --enable-static-nss.  In this case you
: can create a static binary that will use only the services dns and files
: (change /etc/nsswitch.conf for this).  You need to link explicitly against
: all these services. For example:
:   gcc -static test-netdb.c -o test-netdb \
:     -Wl,--start-group -lc -lnss_files -lnss_dns -lresolv -Wl,--end-group
: The problem with this approach is that you've got to link every static
: program that uses NSS routines with all those libraries.
: {UD} In fact, one cannot say anymore that a libc compiled with this
: option is using NSS.  There is no switch anymore.  Therefore it is
: *highly* recommended *not* to use --enable-static-nss since this makes
: the behaviour of the programs on the system inconsistent.

IOW, you will probably have to build glibc yourself if you want to be
able to create binaries which don't require any shared libraries.

Glynn Clements <glynn.clements at virgin.net>

More information about the Haskell-Cafe mailing list