Shared Libraries in ghci

Simon Marlow simonmarhaskell at gmail.com
Fri Feb 8 05:32:09 EST 2008


Bernd Brassel wrote:
> Sorry to ask a C question here, but I could not find an answer on the net.
> 
> How do I create a library that can be used in ghci?
> 
> This is the situation:
> I have a c file coracle.c. I do
> 
> /tmp$ cc -c -o coracle.o coracle.c
> /tmp$ ar rc libcoracle.a coracle.o
> /tmp$ ranlib libcoracle.a
> 
> and then I the library is linked statically with ghc just fine:
> 
> /tmp$ ghc -L/tmp -lcoracle --make COracle.hs
> 
> But if I create a shared library, like this:
> 
> /tmp$ cc -c -shared -o libcoracle.so coracle.c

Normally it's done like this:

  $ gcc -fPIC -c foo.c
  $ gcc -shared -o libfoo.so foo.o

Hope this helps.

Cheers,
	Simon

> then ghci does not like the format:
> 
> /tmp$ ghci -L/tmp -lcoracle COracle.hs
> GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
> Loading package base ... linking ... done.
> Loading object (dynamic) coracle ... failed.
> Dynamic linker error message was:
>    /tmp/libcoracle.so: only ET_DYN and ET_EXEC can be loaded
> Whilst trying to load:  (dynamic) coracle
> Directories to search are:
>    /tmp
> ghc-6.8.2: user specified .o/.so/.DLL could not be loaded.
> 
> In the web I only find bla about which bit in the ELF-header of the
> library tells you that it is ET_DYN or not. But never how to build such
> a library.
> 
> I guess it is too much to hope for a C-freak around here but I am sure a
> semi-freak or quarter-freak will do as well.
> 
> Thanks in advance!
> Bernd
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



More information about the Glasgow-haskell-users mailing list