Tom Hawkins wrote:
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?
No switches, I'm afraid. You'll need to include the complete contents
of libHSrts.a, and whatever packages you're using: probably at least
base and haskell98, i.e. libHSbase.a and libHShasekll98.a respectively.
I don't know if you can include the contents of a .a file directly
when building another .a file, if not you'll need to unpack these
archives and include their contents when building your archive.
Cheers,
Simon
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe