
When I compile my haskell program (on a linux machine) with GHC and send it to a colleague he can't run it because he has a somewhat older version of libc. Is there a GHC switch that I have missed that enables you to statically link the parts of libc that is used by the haskell program? Alternatively have someone other tips for solving this problem? (I'm reluctant to force all my colleagues to install GHC, because of the size and long installation time, and I can't let them use Hugs because I've used some GHC-only features in my program.) Per Larsson

On Sat, 2004-05-15 at 16:08, Per Larsson wrote:
When I compile my haskell program (on a linux machine) with GHC and send it to a colleague he can't run it because he has a somewhat older version of libc. Is there a GHC switch that I have missed that enables you to statically link the parts of libc that is used by the haskell program?
On linux, just give ghc the switch "-optl-static" which passes "-static" to the linker. That will link statically with all libs, not just libc. Duncan

Per Larsson wrote:
[...] Is there a GHC switch that I have missed that enables you to statically link the parts of libc that is used by the haskell program? [...]
Passing "-static" to the GNU linker results in a, well, statically linked program. :-) Using "-optl -static" with GHC does what you want, see: http://haskell.org/ghc/docs/latest/html/users_guide/options-phases.html#FORC... And here the proof: panne@jeanluc:> ghc --make -optl -static Main.hs Chasing modules from: Main.hs Compiling Main ( Main.hs, Main.o ) Linking ... panne@jeanluc:> file a.out a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.5, statically linked, not stripped panne@jeanluc:> ldd a.out not a dynamic executable For non-GNU linkers consult the man pages for "ld", differing linking techniques are one of the most annoying incompatibilities between different *nices IMHO. Cheers, S.

Thanks Duncan and Sven for your helpful answers. Per Larsson 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?

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

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?
Yes, this seems to be the case for some functions in glibc, see e.g.: http://www.busybox.net/lists/busybox/2004-May/011474.html and the reply: http://www.busybox.net/lists/busybox/2004-May/011475.html No idea what this means in practice, though... Cheers, S.

On Sat, May 15, 2004 at 07:44:06PM +0200, Per Larsson wrote:
Thanks Duncan and Sven for your helpful answers.
Per Larsson
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?
Add the options -static -optl-static -ldl to your linking step to make it work. the 'nss' functions (looking up hostnames and users) won't work. but everything else should. I use static haskell compiled binaries on linux all the time. the '-ldl' is the tricky one. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (5)
-
Duncan Coutts
-
Glynn Clements
-
John Meacham
-
Per Larsson
-
Sven Panne