[Haskell-cafe] Use Haskell shared library with foreign exports with dlopen/dlsym

Tobias Neumann mail at tobias-neumann.eu
Mon Sep 8 17:31:02 UTC 2014


> what OS and other things?

I'm on GNU/Linux.

> Also, when calling haskell code as if it were C code, you need to init
> the RTS its using, its not going to magically know you're linking to it
> from haskell.(though maybe you can arrange things to use the pre inited
> hs runtime, but i'm not familiar with how to do so)
> http://www.haskell.org/haskellwiki/Calling_Haskell_from_C

You mean I should foreign import hs_init and call it from within my 
haskell code, then dlopen the library and use dlsym "__stginit_Test" to 
call the foreign imported hs_add_root with it before calling test? (I 
tested that this doesn't fix it)

I'm already calling test from within an initialized runtime system (since 
I call it from haskell code), otherwise I'd probably get no result at all 
and not just an error when dlclose is called and a garbage collection 
occurs.




More information about the Haskell-Cafe mailing list