Mike Thomas mthomas@gil.com.au 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
Hi again.
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.
Thanks for that - I've achieved linker happiness. FYI, I notice that the GCTest stub file has a do..while(0), which I suppose should be optimised away by GCC, but still makes the code less palatable: -------------------------------------------------------- /* Auto generated GreenCard 2 code for FFI */ double prim_my_sin(double arg1) { double res1; do { res1=sin(arg1); return((double)(res1));} while(0); } -------------------------------------------------------- Cheers Mike Thomas
participants (2)
-
Mike Thomas -
Sigbjorn Finne