[Haskell-cafe] GHC linking problems

SevenThunders mattcbro at earthlink.net
Tue Aug 14 21:54:04 EDT 2007

I have a large Haskell/C project that needs to be linked against an even
larger set of C libraries and object files  (OpNet) on a linux box (Fedora
Core 7).  So far I have been able to link my Haskell libraries to some C
test code containing a main function without incident.  However the link
flags are very complex having been extracted from ghc.  (e.g. it requires a
host of -u flags and then a bunch of links to external C libraries including
a long list of Haskell libraries.)  

Unfortunately control over the OpNet compilation and linking process is weak
at best.  Moreover it is not clear how the linking occurs and there is some
suspicion that it ultimately creates a dynamic link library which it loads
from some external process  (the exact calls to gcc are hidden).  During the
OpNet build we get the following error

/usr/lib/ghc-6.6.1/libHSrts.a(Main.o): In function `main':
Main.c:(.text+0x22): undefined reference to `__stginit_ZCMain'
Main.c:(.text+0x43): undefined reference to `ZCMain_main_closure'
collect2: ld returned 1 exit status

I do not get this error when statically linking my libraries to a standalone
C function containing a main() function.  What should I look for?  Are there
known work arounds to this problem?  It's troubling that exporting Haskell
to C should be this problematic.  Unfortunately I can not use ghc to compile
the OpNet code as you might imagine.
View this message in context: http://www.nabble.com/GHC-linking-problems-tf4270650.html#a12155220
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

More information about the Haskell-Cafe mailing list