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

Martin Norbäck d95mback@dtek.chalmers.se
10 Sep 2002 16:14:42 +0200


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


--=-/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:
>=20
> # ghc -fglasgow-exts -c Adder.hs
> # gcc -c -DDLL_IMPORT=3D -I/usr/lib/ghc-5.04/include dllMain.c
> # ld -shared -o adder.so 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
>=20
> and then I get the following:
>=20
> a.out: fatal error: LOOKS_LIKE_GHC_INFO- is incorrectly defined
>=20
> What to do next, I wonder...

Here are the files used so you can test for yourself. Oh, and adder.so
above should be libadder.so.

--=20
Martin Norb=E4ck          d95mback@dtek.chalmers.se             =20
Kapplandsgatan 40       +46 (0)708 26 33 60                   =20
S-414 78  G=D6TEBORG      http://www.dtek.chalmers.se/~d95mback/
SWEDEN                  OpenPGP ID: 3FA8580B

--=-/5xUVEbo3BVdaKwISqhK
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

--=-/5xUVEbo3BVdaKwISqhK
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));

  shutdownHaskell();

  return 0;
}

--=-/5xUVEbo3BVdaKwISqhK
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[]) {
  test(argc,argv);
}

--=-/5xUVEbo3BVdaKwISqhK--

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

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: För information se http://www.gnupg.org/

iD4DBQA9ff5SkXyAGj+oWAsRAqAsAJ0TIuBZ+1cloeFMUKMkScMRgwF9QACXVuiT
BgLYhSN+3eGOOE663UnkrA==
=WTGh
-----END PGP SIGNATURE-----

--=-hj4AbQSxdjUBuwUUZKQz--