[Haskell-cafe] GHC linking problems

SevenThunders mattcbro at earthlink.net
Wed Aug 15 17:52:30 EDT 2007

SevenThunders wrote:
> 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.

Does this error occur because of dynamic linking?  That is if this were all
packed into some library without a main function in C it would try to link
to the Main.o object file in libHSrts.a, which has some unsatisfied links
since there is no main function in the Haskell code.  So does static linking
always fix this?  Is it possible to fix it by providing a dummy main
function in a dynamic link library?  I don't know if the latter is possible
in linux.

View this message in context: http://www.nabble.com/GHC-linking-problems-tf4270650.html#a12171221
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

More information about the Haskell-Cafe mailing list