creating a library from haskell files and a c wrapper in Linux
Tue, 10 Sep 2002 08:33:31 -0700
Speaking solely from the gcc side, if you can capture all the compilation
commands, add "-PIC", and then grab the ld flags and change the options
there, everything should work. This is, obviously, not terribly convenient
but anything that links as a binary should work as a shared library as well.
Simon, am I missing something?
On Tuesday 10 September 2002 08:32, Martin Norbäck wrote:
> tis 2002-09-10 klockan 16.39 skrev Simon Marlow:
> > > tis 2002-09-10 klockan 16.08 skrev Martin Norbäck:
> > > > Now I have done the following:
> > > >
> > > > # ghc -fglasgow-exts -c Adder.hs
> > > > # gcc -c -DDLL_IMPORT= -I/usr/lib/ghc-5.04/include dllMain.c
> > > > # ld -shared -o adder.so Adder.o Adder_stub.o dllMain.o
> > > > -L/usr/lib/ghc-5.04 -lHSbase -lHSbase_cbits -lHSrts -lHSbase -lgmp
> > > > # gcc test.c -L. -ladder
> > > > # env LD_LIBRARY_PATH=. ./a.out
> > > >
> > > > and then I get the following:
> > > >
> > > > a.out: fatal error: LOOKS_LIKE_GHC_INFO- is incorrectly defined
> > > >
> > > > What to do next, I wonder...
> > >
> > > Here are the files used so you can test for yourself. Oh, and adder.so
> > > above should be libadder.so.
> > You can't make a dynamic library containing Haskell code on Unix, sorry.
> > What actually is it you're trying to do?
> I want to make a library that can be used to link against from C code.
> This library contains Haskell code, and I've made some C code to
> interface with the Haskell code, using startupHaskell and
> I want to make a self-contained library (which will contain the Haskell
> run-time code, the Haskell code, and the C interface code) that I can
> link to without having to use ghc to link. I also would like to make
> this library dynamic so that I can dlopen it later.
> When I link the .o files with to produce an executable (with gcc)
> everything works fine. I get a binary that does what it should.
> I don't see the reason why I shouldn't be able to link dynamically
> against the same .o files when they are in a dynamic library.
> And whatever the reason is, how much work do you think it will take to
> fix it? And how easy is it?
M. I. S. Corp.