Linking executables and the library of a Cabal package description

John D. Ramsdell ramsdell at mitre.org
Mon Oct 15 14:32:44 EDT 2007


I'm sure this will be an easy question for those on this list.  What
do you need to add to a Cabal package description so as to allow an
executable in the description to be built from the library it also
describes?  I searched the Cabal documentation many times, but came up
empty handed.

John

$ make
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

exec/Main.hs:3:7:
    Could not find module `A':
      Use -v to see a list of the files searched for.
make: *** [all] Error 1
$ : after cleaning...
$ more `find . -type f ` > ../a.txt
$ cat ../a.txt
::::::::::::::
./a.cabal
::::::::::::::
Name:			a
Version:		1.0
Build-Depends:		base
Exposed-Modules:	A

Executable:		b
Main-Is:		Main.hs
Other-Modules:		A
Hs-Source-Dirs:		exec
::::::::::::::
./Setup.hs
::::::::::::::
import Distribution.Simple
main = defaultMain
::::::::::::::
./Makefile
::::::::::::::
SETUP	= runhaskell Setup.hs

all:	
	if test ! -f .setup-config; then $(SETUP) configure; fi
	$(SETUP) build

Makefile:
	@echo make $@

%:	force
	$(SETUP) $@

.PHONY:	all force
::::::::::::::
./A.hs
::::::::::::::
module A where

a :: Int
a = 3
::::::::::::::
./exec/Main.hs
::::::::::::::
module Main (main) where

import A

main :: IO ()
main =
    print a
$ ghc -h
ghc-6.6.1: unrecognised flags: -h
Usage: For basic information, try the `--help' option.
$ uname -a
Linux goo 2.6.22.9-91.fc7 #1 SMP Thu Sep 27 23:10:59 EDT 2007 i686 i686 i386 GNU/Linux
$ 


More information about the Libraries mailing list