Static linking problem // CentOS 5.5 - GHC 6.12.3

I've installed GHC version 6.12.3 on CentOS 5.5 x86_64. I'm trying to run a very simple Haskell program as CGI following the guide at: http://www.haskell.org/haskellwiki/Practical_web_programming_in_Haskell My .hs file I'm trying to use looks like this: -------------------------------------------------------------- import Network.CGI import Text.XHtml page :: Html page = body << h1 << "Hello World!" cgiMain :: CGI CGIResult cgiMain = output $ renderHtml page main :: IO () main = runCGI $ handleErrors cgiMain -------------------------------------------------------------- If I compile it using dynamic linking I can run it from the command line, since the environment is correct: # ghc haskell_v2.hs --make -o haskell_v2.cgi Linking haskell_v2.cgi ... # ./haskell_v2.cgi Content-type: text/html; charset=ISO-8859-1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> http://www.w3.org/1999/xhtml"
[root@vps-1040050-2953 haskellTest]# However I do of course want to run it through CGI on a webserver. I'm running lighttpd. If I try to run the file compiled above I get "500 - Internal Server Error", most likely since the enviroment is not correct for dynamic linked files: # ldd haskell_v2.cgi librt.so.1 => /lib64/librt.so.1 (0x00002aff22c25000) libutil.so.1 => /lib64/libutil.so.1 (0x00002aff22e2e000) libdl.so.2 => /lib64/libdl.so.2 (0x00002aff23031000) libgmp.so.3 => /usr/lib64/libgmp.so.3 (0x00002aff23236000) libm.so.6 => /lib64/libm.so.6 (0x00002aff2346f000) libc.so.6 => /lib64/libc.so.6 (0x00002aff236f2000) libpthread.so.0 => /lib64/libpthread.so.0 (0x00002aff23a4a000) /lib64/ld-linux-x86-64.so.2 (0x00002aff22a08000) # file haskell_v2.cgi haskell_v2.cgi: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped Hence I wanted to use static linking ( http://www.haskell.org/haskellwiki/Web/Literature/Static_linking ). However trying to compile using the "-optl-static" option fails: # ghc haskell_v2.hs --make -optl-static -fforce-recomp -o haskell_v2.cgi [1 of 1] Compiling Main ( haskell_v2.hs, haskell_v2.o ) Linking haskell_v2.cgi ... /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(HsNet.o): In function `hsnet_getaddrinfo': HsNet.c:(.text+0x11): warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sAwu_info': (.text+0xd45d): warning: Using 'gethostbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syh4_info': (.text+0x4364): warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sygm_info': (.text+0x424f): warning: Using 'gethostent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syx3_info': (.text+0x5318): warning: Using 'sethostent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sxz5_info': (.text+0x12c6): warning: Using 'endhostent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syJY_info': (.text+0x605d): warning: Using 'getnetbyaddr' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sycm_info': (.text+0x3e75): warning: Using 'getnetbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sybC_info': (.text+0x3de7): warning: Using 'getnetent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syyg_info': (.text+0x5458): warning: Using 'setnetent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sxz5_info': (.text+0x1296): warning: Using 'endnetent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syGE_info': (.text+0x5d42): warning: Using 'getprotobynumber' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sylC_info': (.text+0x474f): warning: Using 'getprotoent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syvQ_info': (.text+0x51d8): warning: Using 'setprotoent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sxz5_info': (.text+0x12f6): warning: Using 'endprotoent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syEu_info': (.text+0x5a25): warning: Using 'getprotobyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syAp_info': (.text+0x55c4): warning: Using 'getservbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syCX_info': (.text+0x584c): warning: Using 'getservbyport' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `syoz_info': (.text+0x49ef): warning: Using 'getservent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sytu_info': (.text+0x5098): warning: Using 'setservent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/local/lib/network-2.3/ghc-6.12.3/libHSnetwork-2.3.a(BSD.o): In function `sxz5_info': (.text+0x1326): warning: Using 'endservent' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_create.o): In function `timer_create': (.text+0x124): undefined reference to `pthread_once' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_create.o): In function `timer_create': (.text+0x171): undefined reference to `pthread_attr_init' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_create.o): In function `timer_create': (.text+0x1b8): undefined reference to `pthread_attr_setdetachstate' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0x3f): undefined reference to `pthread_attr_init' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0x4c): undefined reference to `pthread_attr_setstacksize' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0x92): undefined reference to `pthread_create' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0xc6): undefined reference to `pthread_attr_destroy' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_routines.o): In function `__start_helper_thread': (.text+0xd4): undefined reference to `pthread_atfork' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_routines.o): In function `timer_helper_thread': (.text+0x1e1): undefined reference to `pthread_exit' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/librt.a(timer_routines.o): In function `timer_helper_thread': (.text+0x21b): undefined reference to `pthread_create' /usr/haskell//lib/ghc-6.12.3/libHSffi.a(closures.o): In function `init_mparams': /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:2486:0: undefined reference to `pthread_mutex_lock' /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:2490:0: undefined reference to `pthread_mutex_init' /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:2493:0: undefined reference to `pthread_mutex_unlock' /usr/haskell//lib/ghc-6.12.3/libHSffi.a(closures.o): In function `internal_malloc_stats': /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:2861:0: undefined reference to `pthread_mutex_lock' /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:2888:0: undefined reference to `pthread_mutex_unlock' /usr/haskell//lib/ghc-6.12.3/libHSffi.a(closures.o): In function `internal_realloc': /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:3777:0: undefined reference to `pthread_mutex_lock' /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:3819:0: undefined reference to `pthread_mutex_unlock' /usr/haskell//lib/ghc-6.12.3/libHSffi.a(closures.o): In function `internal_memalign': /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:3868:0: undefined reference to `pthread_mutex_lock' /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:3915:0: undefined reference to `pthread_mutex_unlock' /usr/haskell//lib/ghc-6.12.3/libHSffi.a(closures.o): In function `ialloc': /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:3998:0: undefined reference to `pthread_mutex_lock' /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:4052:0: undefined reference to `pthread_mutex_unlock' /usr/haskell//lib/ghc-6.12.3/libHSffi.a(closures.o): In function `dlmalloc': /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:4085:0: undefined reference to `pthread_mutex_lock' /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:4186:0: undefined reference to `pthread_mutex_unlock' /usr/haskell//lib/ghc-6.12.3/libHSffi.a(closures.o): In function `dlfree': /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:4211:0: undefined reference to `pthread_mutex_lock' /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:4285:0: undefined reference to `pthread_mutex_unlock' /usr/haskell//lib/ghc-6.12.3/libHSffi.a(closures.o): In function `dlmalloc_trim': /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:4362:0: undefined reference to `pthread_mutex_lock' /home/ian/zz/ghc-6.12.3/libffi/build/src/dlmalloc.c:4364:0: undefined reference to `pthread_mutex_unlock' /usr/haskell//lib/ghc-6.12.3/libHSffi.a(closures.o): In function `dlmmap': /home/ian/zz/ghc-6.12.3/libffi/build/src/closures.c:438:0: undefined reference to `pthread_mutex_lock' /home/ian/zz/ghc-6.12.3/libffi/build/src/closures.c:440:0: undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc_eh.a(unwind-dw2.o): In function `uw_init_context_1': (.text+0x1be5): undefined reference to `pthread_once' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__deregister_frame_info_bases': (.text+0x10bc): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__deregister_frame_info_bases': (.text+0x10cd): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_table_bases': (.text+0x117f): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_bases': (.text+0x1238): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `_Unwind_Find_FDE': (.text+0x14b6): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `_Unwind_Find_FDE': (.text+0x14c7): undefined reference to `pthread_mutex_lock' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_table_bases': (.text+0x119e): undefined reference to `pthread_mutex_unlock' /usr/lib/gcc/x86_64-redhat-linux/4.1.2/libgcc_eh.a(unwind-dw2-fde-glibc.o): In function `__register_frame_info_bases': (.text+0x1257): undefined reference to `pthread_mutex_unlock' collect2: ld returned 1 exit status There are two main categories of error messages above: 1 : ...requires at runtime the shared libraries from the glibc version used for linking 2a : undefined reference to `pthread_....' 2b : undefined reference to `pthread_mutex_lock' I've had no luck in sorting out how to solve this and an quite new to both Linux and Haskell. I never managed to install (build from source failed) the entire Haskell Platform on CentOS 5.5, is that needed? Anyone has got any idea what might causing these errors? Regards, Frode

frode k
However I do of course want to run it through CGI on a webserver. I'm running lighttpd. If I try to run the file compiled above I get "500 - Internal Server Error", most likely since the enviroment is not correct for dynamic linked files:
Why wouldn't the environment (i.e. available dynamic libraries) be correct for the web server?
Hence I wanted to use static linking ( http://www.haskell.org/haskellwiki/Web/Literature/Static_linking ). However trying to compile using the "-optl-static" option fails: There are two main categories of error messages above:
1 : ...requires at runtime the shared libraries from the glibc version used for linking
Yes, Linux (or rather, glibc) doesn't really support static linking any more, and relies on hard-coded paths to libraries for unicode stuff and name resolution and authentication. You can override this with environment variables, though. Perhaps this is helpful: http://blog.malde.org/index.php/2010/05/22/snagged/
2a : undefined reference to `pthread_....'
2b : undefined reference to `pthread_mutex_lock'
ghc ... -optl-static -optl-pthread ^^^^^^^^^^^^^ Not sure why you have to add this manually, but it's been this way for years - at least since ghc 6.8, I think. -k -- If I haven't seen further, it is by standing in the footprints of giants

On Wed, Mar 16, 2011 at 8:05 AM, Ketil Malde
frode k
writes: However I do of course want to run it through CGI on a webserver. I'm running lighttpd. If I try to run the file compiled above I get "500 - Internal Server Error", most likely since the enviroment is not correct for dynamic linked files:
Why wouldn't the environment (i.e. available dynamic libraries) be correct for the web server?
You are right, dynamically linked files do work. It must be something with Lighttpd that prevents the Haskell compiled CGI code to be executed. When I moved the exact same CGI file to the cgi-bin directory on my Apache it ran without problems. If I do find out why I can not run Haskell CGI on Lighttpd I will send an update on this. Thanks for your feedback. Regards, Frode

Why wouldn't the environment (i.e. available dynamic libraries) be correct for the web server?
beacuse it runs CGI programs in a chroot jail? Then you need to copy the .so files into the jail, cf. http://www.cyberciti.biz/tips/howto-setup-lighttpd-php-mysql-chrooted-jail.h... J.W.

I had missed out some settings in the configuration files of lighttpd. Summary: - I renamed the Haskell test file to "haskell.hcgi" - I edited "/etc/lighttpd/conf.d/cgi.conf" and added two entries in the cgi.assign section, one for ".hcgi" and one for ".hs" (the latter one only to enable running of .hs files / uncompiled Haskell code for testing purposes). - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - cgi.assign = ( ".pl" => "/usr/bin/perl", ".cgi" => "/usr/bin/perl", ".rb" => "/usr/bin/ruby", ".erb" => "/usr/bin/eruby", ".py" => "/usr/bin/python", ".hcgi"=> "", ".hs" => "/usr/haskell/bin/runhaskell") - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - After a lighttpd restart I can now access both .hs files (for testing purposes, since performance assumingly won't be top notch here) and compiled .hcgi files. If I did not need to use perl for .cgi I could have change the setting for ".cgi" pointing to empty ("") in stead of adding a new entry for ".hcgi" / Haskell CGI. Regards, Frode
participants (3)
-
frode k
-
J. Waldmann
-
Ketil Malde