[Haskell-cafe] Creating static libraries using GHC

Tom Hawkins tomahawkins at gmail.com
Tue Jan 17 22:58:01 EST 2006


I have a chunk of Haskell code I would like wrap up and distribute as
a library.  Is there a way to build a static library (*.a) that
includes my code plus the Haskell runtime, which C programs can easily
link against?  Here is what I have tried so far...

ghc --make -fffi MyLib   # Builds MyLib.o and MyLib_stub.o.
gcc -c -I/usr/local/lib/ghc-6.4.1/include MyLibWrapper.c
ar -r libMyLib.a MyLib.o MyLib_stub.o MyLibWrapper.o

This works fine when I use ghc to compile and link a C program...

ghc main.c libMyLib.a

But if I use gcc, it throws a lot of unresolved references.  I have no
problem compiling with ghc, but the folks using my library probably
won't have it installed.

I added -v to ghc to see how it calls gcc; it seems to link in
different libraries based on what Haskell libraries are being used,
and it undefines a bunch is symbol references.  Are there any switches
to have ghc return a single archive with everything included?

Please excuse my ignorance of the linking process.  Thanks for any help!

-Tom


More information about the Haskell-Cafe mailing list