
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 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

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@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Any chance of documenting your experience on the GHC user documentation page? http://haskell.org/haskellwiki/GHC (under "collaborative documentation") A kind of how-to that worked for you, with pointers to relevant manual parts etc. Simon | -----Original Message----- | From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users-bounces@haskell.org] On Behalf Of | Bernd Brassel | Sent: 08 February 2008 10:53 | To: Simon Marlow | Cc: glasgow-haskell-users@haskell.org | Subject: Re: Shared Libraries in ghci | | Simon Marlow wrote: | | > Normally it's done like this: | > | > $ gcc -fPIC -c foo.c | > $ gcc -shared -o libfoo.so foo.o | > | > Hope this helps. | | Right away! Big Thanks! | | Bernd | _______________________________________________ | Glasgow-haskell-users mailing list | Glasgow-haskell-users@haskell.org | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Simon Peyton-Jones wrote:
Any chance of documenting your experience on the GHC user documentation page? http://haskell.org/haskellwiki/GHC (under "collaborative documentation") A kind of how-to that worked for you, with pointers to relevant manual parts etc.
Simon
Is this something that would go to GHC/FAQ/4 about the GHCI?

Bernd Brassel wrote:
Simon Peyton-Jones wrote:
Any chance of documenting your experience on the GHC user documentation page? http://haskell.org/haskellwiki/GHC (under "collaborative documentation") A kind of how-to that worked for you, with pointers to relevant manual parts etc.
Simon
Is this something that would go to GHC/FAQ/4 about the GHCI?
I'd put it in here: http://haskell.org/haskellwiki/GHC/Using_the_FFI Cheers, Simon
participants (3)
-
Bernd Brassel
-
Simon Marlow
-
Simon Peyton-Jones