Packages (again)

Simon Marlow simonmar@microsoft.com
Mon, 9 Sep 2002 17:12:50 +0100


> (adding the linker flags to ld_opts does not make a
> difference for the rest of the story)
>=20
> To make everything work with ghc, I do the following:
>=20
>   * gcc -c foo.c -o foo.o
>=20
>   * ghc -c Foo.hs -o Foo.o
>=20
>   * ar -rsv libHSFoo.a foo.o Foo.o
>=20
> Now, I can compile programs with "ghc -package foo". Great!
>=20
> However, when I try ghci, it does not work. So, first, I
> make a .o version of libHSFoo.a:
>=20
>   * gld -r --whole-archive -o HSFoo.o libHSFoo.a
>=20
> But, when I start "ghci -package foo", it does not find the
> library libbar! It does not even find it when I say "ghci
> -L/path/to/libs -lbar -package foo"!

You should add "bar" to the 'extra_libraries' field of the package
config, because otherwise GHCi doesn't know about the dependency.

> No worries, we can make ghci read a .so file instead:
>=20
>   * rm HSFoo.o
>=20
>   * gcc -shared Foo.o foo.o -L/path/to/libs -lbar -o libHSFoo.so
>=20
> Starting ghci now loads libHSFoo.so, and everything works
> wonderfully.

I'm highly surprised if this really works.  Can you actually call
functions from the Foo module without it crashing?

Cheers,
	Simon