creating packages

Simon Marlow [email protected]
Tue, 29 May 2001 11:17:43 +0100


> Who could, please, consult on the package setting in  ghc-5.00.1
> ?
> Let the project  foo  consist of the files   /t/A.hs
>                                              /t/t1/B.hs,
> B  import  A,
> the user work in  /u/  and exploit  foo  in compiling, linking
> and interpreting.
>=20
> Everything seems to work below, except  `ghci -package'=20
> and                                     `ghc -c -package-name foo'
>=20
> (ghc-5.00.1 compiled from source for Linux, i386-unknown).=20
> What I do:
>=20
> -------------------------------------------------
> * apply   ghc --make B;

That should be=20
	=09
	ghc -package-name foo --make B.

because you're building modules for package 'foo'.

> * move all  *.o  *.hi  files to   /t/export/ ;
> * command  cd /t/export/
>            ar -q libHSfoo.a *.o    (creating a library)
>=20
> * create a file  p.txt  containing
>=20
>   Package {name            =3D "foo",
>            import_dirs     =3D ["/t/export" ],
>            source_dirs     =3D [],
>            library_dirs    =3D ["/t/export" ],
>            hs_libraries    =3D ["HSfoo"],
>            extra_libraries =3D [],
>            include_dirs    =3D [],    c_includes      =3D [],
>            package_deps    =3D [],    extra_ghc_opts  =3D [],
>            extra_cc_opts   =3D [],    extra_ld_opts   =3D []
>           }
>   and apply                       ghc-pkg -a < p.txt
>   adding a package  foo  to  ghc.
> -------------------------------------------------
>=20
> Then, for the user module   /u/Main.hs
> importing  B,
> the user commands    cd /u;   ghc -c -package foo Main.hs
>                               ghc -o run Main.o -package foo
> - and it works.
> But              ghci -package foo
> yields
>   Loading package foo ... can't find .o or .so/.DLL for: HSfoo=20
>   (libHSfoo.so: cannot open shared object file: No such file=20
> or directory)

GHCi can't load .a files (at the moment).  You can build a .o file from
a .a file like so (with GNU ld):

	ld --whole-archive libHSfoo.a -o libHSfoo.o

Cheers,
	Simon