I've managed to load a shared object (compiled from a Haskell source via -rdynamic) with the following code:
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE MagicHash, UnboxedTuples #-}
module Main where
import GHC.Exts ( addrToAny# )
import GHC.Ptr ( Ptr(..) )
import System.Info ( os, arch )
import Encoding
import GHCi.ObjLink
import Debug.Trace
main :: IO ()
main = do
traceM "before initObjLinker"
initObjLinker
traceM "before loadObj"
loadObj "/Users/saurabhnanda/projects/test-plugins/test-plugins/app/PluginMarkup.o"
traceM "after loadObj"
-- NOTE: I've hardcoded the symbol name that I obtained from running `symbols PluginMarkup.o`
sym <- lookupSymbol "PluginMarkup_foliage_info"
traceM "after lookupsymbol"
traceM (show sym)
I'm getting the following output, which mean that I'm probably getting the Ptr to the function.
Question is, how do I run the function in the same Haskell environment/runtime? The underlying function is actually `foliage :: UtcTime -> Html`
-- Saurabh.