Greencard, GHC and FFI.

Mike Thomas
Sat, 17 Mar 2001 12:20:34 +1000

Hi all.

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.

Using the example from the green-card doc:
module GCTest where
import StdDIS
%fun my_sin :: Double -> Double
%code res1=sin(arg1);

Compiling for target FFI:
green-card -c GCTest.gc -o GCTest.hs --target ffi
ghc -c GCTest.hs -fglasgow-exts

Linking with this main module:
module Main(main) where
import GCTest
main :: IO()
main = putStrLn (show (my_sin (20.0)))

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'
StdDIS.o(.text+0x549):fake: undefined reference to `prim_free'
StdDIS.o(.text+0x600):fake: undefined reference to `prim_allocCharStar'
StdDIS.o(.text+0x731):fake: undefined reference to `prim_readCharAddr'
StdDIS.o(.text+0xc84):fake: undefined reference to `prim_malloc'
StdDIS.o(.text+0xd38):fake: undefined reference to `access_prim_malloc_res1'
StdDIS.o(.text+0xdec):fake: undefined reference to
StdDIS.o(.text+0xea0):fake: undefined reference to
StdDIS.o(.text+0x1206):fake: undefined reference to `prim_writeCharAddr'
collect2: ld returned 1 exit status

Where have I gone wrong?


Mike Thomas.