Greencard, GHC and FFI.

Sigbjorn Finne [email protected]
Sat, 17 Mar 2001 10:01:12 +0100


Mike Thomas [email protected] writes:
>
> I'm having trouble with using green-card 2 on Windows
> with GHC-4.08.2.  As the default output for -target ghc seems
> to be for the C back-end rather than native code, I thought I would
> try the FFI target.
>
.... example code deleted
>
> I get
>
> $ ghc main.hs -o main.exe GCTest.o StdDIS.o -package lang -package
greencard
> ---------------------------------------------
> Compilation IS NOT required
> GCTest.o(.text+0x7f):fake: undefined reference to `prim_my_sin'
> ....

Hi,

Greencard lets you write C and Haskell in one source file. When using GHC's
C back end, it is possible to combine the two in one source file (via GHC's
_casm_s.) The FFI doesn't let you do this, but requires you to provide
the C bits separately, and link the Haskell code to it via 'foreign'
declarations.

So, when using GC's FFI backend, it generates two source files for you
(and some header files) - in your case, GCTest.hs and GCTest_stub.c.
To achieve linker happiness, you need to compile up the latter and include
it on the link line *and* drop StdDIS.o from that link line.

hth
--sigbjorn