
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: https://github.com/haskell/cabal/issues/4435 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: https://github.com/nh2/call-haskell-from-anything/blob/0ba6737ea17a45e59704d.... That links it explicitly like you planned to do. According to https://github.com/nh2/call-haskell-from-anything/issues/19#issuecomment-263... 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: https://github.com/haskell/cabal/blob/db26fa21cba92097d9fdeb580ddf797c35af8e... Hope this helps! Niklas