Fri, 13 Oct 2000 08:43:26 -0500
So if I understand this correctly, I'm doing it wrong, but that's o.k.
because even if I wasn't it still wouldn't work :)
This brings up a larger question, should I even be trying to do this?
Here is the situation:
A colleague of mine had a couple of little routines that he needed
(something simple to do in Haskell but a pain in C).
I quickly zipped out the solution in a few lines of Haskell, but now I would
like to give him something usable from C.
My question is:
What format can I (and/or should I) give him the routines in...
C code he can compile? This would be best, but I couldn't figure out how to
make this work.
An object file he can link in? This is what I was attempting.
A com object? (I don't have any experience with com)
Thanks for your help -
(913) 385-5700 ext.20 Fax (913) 385-5701
From: Sigbjorn Finne [mailto:email@example.com]
Sent: Thursday, October 12, 2000 12:18 PM
Subject: RE: C main
Simon Marlow writes:
> > Could someone instruct me on (or point me to) the correct ghc
> > command line for calling haskell from C?
> > ...
> You can use ghc just like you would use gcc to compile up
> your C program,
> then use ghc again to link the whole program with the Haskell
> module(s). The -no-hs-main flag shouldn't be necessary, as
> far as I can tell. eg.
> $ ghc -c main.c
> $ ghc -c HaskellStuff.hs
> $ ghc main.o HaskellStuff.o
That will (sort of) work if you also insist that HaskellStuff.hs
implements Main.main. As the name suggests, -no-hs-main takes care
of the case when HaskellStuff.hs doesn't. (Well almost, the 4.08 driver
contains a bug in setupLinkOpts(); __init_PrelMain should be handled
the same way as PrelMain_mainIO_closure. )
In either case, you need to make sure that the RTS is started up,
since you're not using the RTS-supplied main(). The HDirect distribution
contains an example of this in examples/server/, but notice that the
4.08 RTS' startupHaskell() signature has changed to also take an extra
'module root' argument. However, even with that change, 4.08
compiled code crashes when running (4.05 works fine), which leads
me to believe there's something else going on here :-) This is on
the same platform that Brett originally reported the problem on.
btw, 4.05 contained a bug in this area which made -no-hs-main only
work when linking with -static. 4.08 seems to have inherited it, i.e.,
in prepareWin32DllLink(), the condition for pushing Main.dll_o and
PrelMain.dll_o onto @Link_file should be ($linking_main && !$NoHaskellMain)
and not just $linking_main