creating a library from haskell files and a c wrapper in Linux

Simon Marlow simonmar@microsoft.com
Tue, 10 Sep 2002 16:45:05 +0100


> I want to make a library that can be used to link against from C code.
>=20
> This library contains Haskell code, and I've made some C code to
> interface with the Haskell code, using startupHaskell and
> shutDownHaskell.
>=20
> I want to make a self-contained library (which will contain=20
> the Haskell
> run-time code, the Haskell code, and the C interface code) that I can
> link to without having to use ghc to link. I also would like to make
> this library dynamic so that I can dlopen it later.
>=20
> When I link the .o files with to produce an executable (with gcc)
> everything works fine. I get a binary that does what it should.
>=20
> I don't see the reason why I shouldn't be able to link dynamically
> against the same .o files when they are in a dynamic library.
>=20
> And whatever the reason is, how much work do you think it will take to
> fix it? And how easy is it?

It's not easy, I'm afraid.  The ELF dynamic linking mechanism is rather =
arcane and imposes a very C-like view of things on object files.  Last =
time I looked into this, I concluded that it couldn't be done without =
sacrificing some of GHC's low-level optimisations (specifically, placing =
code next to data), and even then it would still be a lot of work. =20

However, I've been surprised before by what dynamic linkers can do, so =
it might be worth looking into again.  Anwyay, take a look through the =
archives of this list for more details.

Cheers,
	Simon