Linking executables and the library of a Cabal package description

Duncan Coutts duncan.coutts at
Tue Oct 16 20:37:48 EDT 2007

On Tue, 2007-10-16 at 20:09 -0400, John D. Ramsdell wrote:
> Duncan Coutts <duncan.coutts at> writes:
> > I think the problem here is search paths. Try adding . to the
> > Hs-Source-Dirs, or alternatively moving everything into the root dir
> > rather than under exec.
> If you add . to the Hs-Source-Dirs, you build module A twice, once for
> the library, and once for the building of b.  Notice b is not linked
> with the library.


There is a design choice here. If you link with the library you cannot
use private modules. If you go direct to the source you can use anything
but have to build twice.

To link with the lib, use a separate .cabal file that has an executable.

> $ runhaskell Setup.hs build
> Preprocessing library a-1.0...
> Preprocessing executables for a-1.0...
> Building a-1.0...
> [1 of 1] Compiling A                ( A.hs, dist/build/A.o )
> /usr/bin/ar: creating dist/build/libHSa-1.0.a
> [1 of 2] Compiling A                ( A.hs, dist/build/b/b-tmp/A.o )
> [2 of 2] Compiling Main             ( exec/Main.hs, dist/build/b/b-tmp/Main.o )
> Linking dist/build/b/b ...
> $
> > This smells like a bug in cabal to me.
> Time for me to submit a bug report?

For the search path problem, yes.

So looking at the code, it seems we add '.' as a default, but if you set
any hs-src-dirs explicitly then you don't get the '.' default, you have
to add that explicitly.

Perhaps this is the right behaviour. It's a bit confusing though.


More information about the Libraries mailing list