[Haskell-cafe] Haskell plugin dynamic linking issue
mail at nh2.me
Mon Apr 10 13:50:34 UTC 2017
I'm not sure if it's the solution to your problem already, but there's a
Cabal bug that makes it not pass cc-options and ld-options to GHC as
You need to additionally pass these options as `ghc-options: "-optl
-lyourlib"` if you want to be sure.
Further, looking at an example I have around, my cabal `library` output
(say I have mypackage.cabal with a "library" in there, it's called
"dist/build/libHSmypackage-...so") link against things like
libHSghc-prim, but not against the RTS (libHSrts...so). I think this
makes sense, because as far as I can tell, the RTS is only linked in
when you compile the final executable, and which RTS .so file is chosen
depends on whether you link in the standard runtime, the -threaded
runtime, the debug runtime, etc.
So I believe that when loading Haskell from C you will have to dlopen()
the RTS you want explicitly, before loading your own .so file. You
probably also need to load the RTS with the RTLD_GLOBAL dlopen flag so
that when you later load your .so, it can see the RTS symbols.
An alternative is probably to add HSrts-ghc-VERSION to
`extra-libraries`, like I do here:
That links it explicitly like you planned to do.
there is now a `foreign-library` stanza in Cabal that is supposed to
free you of manually having to link/load the RTS. I haven't tried it
yet, since at the time that comment was written, it wasn't released yet.
Now it might be.
Detail documentation of that feature:
Hope this helps!
More information about the Haskell-Cafe