Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding a haskell interpreter (hint) as dynamic library, useable from C++: Missing Interpreter.dyn_hi
    primarykey
    data
    text
    <p>I want to create a haskell interpreter that I can use from C++ on linux.</p> <p>I have a file FFIInterpreter.hs which implements the interpreter in haskell and exports the functions via FFI to C++.</p> <pre><code>module FFIInterpreter where import Language.Haskell.Interpreter import Data.IORef import Foreign.StablePtr import Foreign.C.Types import Foreign.C.String import Control.Monad import Foreign.Marshal.Alloc type Session = Interpreter () type Context = StablePtr (IORef Session) foreign export ccall createContext :: CString -&gt; IO Context createContext :: CString -&gt; IO Context createContext name = join ((liftM doCreateContext) (peekCString name)) where doCreateContext :: ModuleName -&gt; IO Context doCreateContext name = do let session = newModule name _ &lt;- runInterpreter session liftIO $ newStablePtr =&lt;&lt; newIORef session newModule :: ModuleName -&gt; Session newModule name = loadModules [name] &gt;&gt; setTopLevelModules [name] foreign export ccall freeContext :: Context -&gt; IO () freeContext :: Context -&gt; IO () freeContext = freeStablePtr foreign export ccall runExpr :: Context -&gt; CString -&gt; IO CString runExpr :: Context -&gt; CString -&gt; IO CString runExpr env input = join ((liftM newCString) (join (((liftM liftM) doRunExpr) env (peekCString input)))) where doRunExpr :: Context -&gt; String -&gt; IO String doRunExpr env input = do env_value &lt;- deRefStablePtr env tcs_value &lt;- readIORef env_value result &lt;- runInterpreter (tcs_value &gt;&gt; eval input) return $ either show id result foreign export ccall freeString :: CString -&gt; IO () freeString :: CString -&gt; IO () freeString = Foreign.Marshal.Alloc.free </code></pre> <p>When I compile the whole project with ghc, everything works fine. I use the following command:</p> <pre><code>ghc -no-hs-main FFIInterpreter.hs main.cpp -lstdc++ </code></pre> <p>But the haskell module is only a small piece of the C++ project and I don't want the whole project to depend on ghc.</p> <p>So I want to build a dynamic library with ghc and then link it to the project using g++.</p> <pre><code>$ ghc -shared -fPIC FFIInterpreter.hs module_init.c -lstdc++ [1 of 1] Compiling FFIInterpreter ( FFIInterpreter.hs, FFIInterpreter.o ) Linking a.out ... /usr/bin/ld: /usr/lib/haskell-packages/ghc/lib/hint-0.3.3.2/ghc-7.0.3/libHShint-0.3.3.2.a(Interpreter.o): relocation R_X86_64_32S against `.data' can not be used when making a shared object; recompile with -fPIC /usr/lib/haskell-packages/ghc/lib/hint-0.3.3.2/ghc-7.0.3/libHShint-0.3.3.2.a: could not read symbols: Bad value collect2: ld gab 1 als Ende-Status zurück </code></pre> <p>So I added the -dynamic keyword, but that also doesn't work:</p> <pre><code>$ ghc -dynamic -shared -fPIC FFIInterpreter.hs librarymain.cpp -lstdc++ FFIInterpreter.hs:3:8: Could not find module `Language.Haskell.Interpreter': Perhaps you haven't installed the "dyn" libraries for package `hint-0.3.3.2'? Use -v to see a list of the files searched for. </code></pre> <p>I searched my system for Interpreter.dyn_hi but didn't find it. Is there a way to get it? I also tried to install hint manually, but this also doesn't deliver the Interpreter.dyn_hi file.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload