[Haskell-cafe] Haskell plugin dynamic linking issue
lanablack at amok.cc
Mon Apr 10 14:16:09 UTC 2017
On 10/04/17 13:50, Niklas Hambüchen wrote:
> 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
> ghc-options correctly:
> 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.
> According to
> 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!
Unfortunately, adding rts to extra-libraries section doesn't help. Now I
get a build error from cabal:
Process exited with code: ExitFailure 1
Logs have been written to:
Cabal-simple_mPHDZzAJ_18.104.22.168_ghc-8.0.2: Missing dependency on a
* Missing C library: HSrts-ghc8.0.2
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the
already installed but in a non-standard location then you can use
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
Relevant cabal file options:
ghc-options: -Wall -Werror -shared -fPIC -dynamic
Note that this is a library, not an executable as in
More information about the Haskell-Cafe