Packages (again)
Koen Claessen
koen@cs.chalmers.se
Mon, 9 Sep 2002 17:32:15 +0200 (MET DST)
Hi all,
Now, I am almost done with trying to install this package I
am working on. But, somehow, I can't get it to work for both
ghc and ghci.
I have the following simplified situation:
* a Haskell module, Foo.hs
* a C file, foo.c
* a C library that foo.c needs, /path/to/libs/libbar.so
(I only have a .so version of the library.)
I configured the package file as follows:
>>>
Package {
name = "foo",
import_dirs = ["FooPath"],
source_dirs = ["FooPath"],
library_dirs = ["FooPath"],
hs_libraries = ["HSFoo"],
extra_libraries = [],
include_dirs = [],
c_includes = [],
package_deps = [],
extra_ghc_opts = ["-L/path/to/libs", "-lbar"],
extra_cc_opts = [],
extra_ld_opts = []
}
<<<
(adding the linker flags to ld_opts does not make a
difference for the rest of the story)
To make everything work with ghc, I do the following:
* gcc -c foo.c -o foo.o
* ghc -c Foo.hs -o Foo.o
* ar -rsv libHSFoo.a foo.o Foo.o
Now, I can compile programs with "ghc -package foo". Great!
However, when I try ghci, it does not work. So, first, I
make a .o version of libHSFoo.a:
* gld -r --whole-archive -o HSFoo.o libHSFoo.a
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"!
No worries, we can make ghci read a .so file instead:
* rm HSFoo.o
* gcc -shared Foo.o foo.o -L/path/to/libs -lbar -o libHSFoo.so
Starting ghci now loads libHSFoo.so, and everything works
wonderfully.
Sadly, when I try to compile something with ghc now, it
tries to load the .so version too (instead of the .a
version) and gets mad at me.
What should I do?
/Koen.