Haskell runtime in shared library?

Simon Marlow marlowsd at gmail.com
Fri Jan 30 06:25:40 EST 2009


Patrick LeBoutillier wrote:

> I'm trying to make a shared library containing the Haskell runtime,
> but no Haskell code per se.
> This shared library would then dynamically load other shared libraries
> containing conpiled Haskell code.
> Here is some pseudo code:
> 
> In my_program:
>  dlopen('my_haskell_runtime.so', RT_GLOBAL) ;
>  hs_init(...) ;
> 
> then later, in my_haskell_runtime.so:
>  dlopen('my_haskell_module.so') ;
>  __stginit_MyModule();
> 
> 
> I've found some great information about FFI stuff here:
>  http://www.haskell.org/ghc/docs/latest/html/users_guide/ffi-ghc.html#using-own-main
> and here:
>  http://blog.haskell.cz/pivnik/building-a-shared-library-in-haskell/
> but I can't seem to find examples where the runtime is in a different
> shared object from the Haskell code/module.
> 
> Is this possible to do something like this using GHC?  If so, where
> can I find more information of how
> exactly to link my_haskell_runtime.so and my_haskell_module.so?

What you're trying to do is quite experimental and not fully supported 
right now.  In order to put Haskell code in shared objects, you have to 
build the code in a special way (flags -dynamic -fPIC).  The build system 
has some support for building shared libraries: try configuring with 
--enable-shared.  If this works, you'll get all the libraries built two 
ways: static and shared.

See this ticket for more info:

http://hackage.haskell.org/trac/ghc/ticket/1876

Cheers,
	Simon


More information about the Glasgow-haskell-users mailing list