[Haskell-cafe] Re: Cabal and linking with static libs (.a files)

Simon Marlow simonmarhaskell at gmail.com
Fri Jun 9 11:22:18 EDT 2006

Ketil Malde wrote:
> (Reposted to café - my -libraries mail seems to have gotten lost along
> the way)

> I'm building an interface to a C library, which comes in the form of
> two .a files.  I can't seem to get Cabal to link statically with
> these, so that the resulting package (libHSfoo-v.v.a) is self
> contained. 
> I've tried fiddling with Cabal's ld-options and extra-libraries, but
> so far with no success - loading my package either results in GHC
> looking for (and failing to find) .so files, or "unknown symbol".

A static library doesn't normally specify what it links to, that all 
happens at link time.  So if you say -optl-static when linking your 
program, it won't have any dependencies on shared libraries.

What you actually want to do, I suspect, is to include verbatim copies 
of the .a dependencies in your (binary) Cabal package, to make it 
self-contained.  Cabal doesn't have a way to do that at the moment.  But 
it's quite easy: just copy the .a files from /usr/lib (or wherever) and 
put them in the same place as your libHSpackage.a.

> PS: did --user stop working (with GHC 20060607)?  I'm adding --user to
> both 'configure' and 'install', but Cabal still wants to put things in
> /usr/local. 

I don't think anything changed: --user never changed the install prefix, 
it only ever changed where dependencies are found.  To install in your 
home dir, you also need to say --prefix=$HOME.


More information about the Haskell-Cafe mailing list