creating a library from haskell files and a c wrapper in Linux

Martin Norbäck
10 Sep 2002 16:14:42 +0200

Content-Type: multipart/mixed; boundary="=-/5xUVEbo3BVdaKwISqhK"

Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

tis 2002-09-10 klockan 16.08 skrev Martin Norb=E4ck:
> Now I have done the following:
> # ghc -fglasgow-exts -c Adder.hs
> # gcc -c -DDLL_IMPORT=3D -I/usr/lib/ghc-5.04/include dllMain.c
> # ld -shared -o 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=3D. ./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
above should be

Martin Norb=E4ck             =20
Kapplandsgatan 40       +46 (0)708 26 33 60                   =20
S-414 78  G=D6TEBORG
SWEDEN                  OpenPGP ID: 3FA8580B

Content-Disposition: attachment; filename=Adder.hs
Content-Type: text/x-haskell; name=Adder.hs; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

module Adder where

adder :: Int -> Int -> IO Int  -- gratuitous use of IO
adder x y =3D return (x+y)

foreign export ccall adder :: Int -> Int -> IO Int

Content-Disposition: attachment; filename=dllMain.c
Content-Type: text/x-c; name=dllMain.c; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

#include <stdio.h>
#include "Adder_stub.h"

#include "RtsAPI.h"

extern void __stginit_Adder ( void );

int test(int argc, char *argv[])
  int i;

  startupHaskell(argc, argv, __stginit_Adder);

  printf("%d", adder(1,2));


  return 0;

Content-Disposition: attachment; filename=test.c
Content-Type: text/x-c; name=test.c; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

int main(int argc, char* argv[]) {


Content-Type: application/pgp-signature; name=signature.asc

Version: GnuPG v1.0.6 (GNU/Linux)
Comment: För information se