[Haskell-cafe] Compiling a haskell project as a shared library and loading it in C/C++

35 views
Skip to first unread message

Farid Neshat

unread,
Sep 1, 2012, 12:13:46 AM9/1/12
to haskel...@haskell.org
So I'm trying to follow [this blog][1]. So I tried the code, couldn't
compile the haskell part, probably due to the fact the guide uses
version 6, but I have version 7 of ghc. By changing the paramaters I
could compile it with the following:

ghc --make -dynamic -shared -fPIC -no-hs-main -optl '-shared' -optc
'-DMODULE=Test' -o Test.so Test.hs module_init.c

But the when trying to load it, on dlopen, I get the following error:

/usr/lib/ghc/ghc-prim-0.2.0.0/libHSghc-prim-0.2.0.0-ghc7.4.1.so:
undefined symbol: stg_forkOnzh

I suspect it's because the haskell runtime is not linked to the shared
library but adding -L/usr/lib/ghc/ didn't really help. I searched a
lot, but couldn't find anymore example that somebody have done this.
[Here's also some docs][2] for compiling shared libraries:

[1]: http://weblog.haskell.cz/pivnik/building-a-shared-library-in-haskell
[2]: http://www.haskell.org/ghc/docs/7.4.1/html/users_guide/using-shared-libs.html

_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

A.M.

unread,
Sep 2, 2012, 9:01:11 PM9/2/12
to haskel...@haskell.org
On 09/01/2012 12:13 AM, Farid Neshat wrote:
> So I'm trying to follow [this blog][1]. So I tried the code, couldn't
> compile the haskell part, probably due to the fact the guide uses
> version 6, but I have version 7 of ghc. By changing the paramaters I
> could compile it with the following:
>
> ghc --make -dynamic -shared -fPIC -no-hs-main -optl '-shared' -optc
> '-DMODULE=Test' -o Test.so Test.hs module_init.c

You need to link against the haskell runtime:

ghc --make -dynamic -shared -fPIC -no-hs-main -o X.so
-optl-Wl,-rpath,/usr/lib/ghc/ -lHSrts_debug-ghc7.4.1

Cheers,
M
Reply all
Reply to author
Forward
0 new messages