
I've written a library, and a simple program to demonstrate it. I can write the cabal file for the library, but I can't get the executable section right. How can I tell it to use the library defined herein?

Harry,
Here is a complete cabal file for something I am working on now... it
contains some libraries and three executables that use the library. It's a
WIP for me BUt it works and I can even use it from Leksah by creating a
workspace and adding this hexwax.cabal file as a Package.
It's long but concise!
----
-- Initial hexwax.cabal generated by cabal init. For further
-- documentation, see http://haskell.org/cabal/users-guide/
-- The name of the package.
name: hexwax
-- The package version. See the Haskell package versioning policy (PVP)
-- for standards guiding when and how versions should be incremented.
-- http://www.haskell.org/haskellwiki/Package_versioning_policy
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version: 0.1.0.0
-- A short (one-line) description of the package.
synopsis: Hexwax ExnapdIO-USB wrapper
-- A longer description of the package.
-- description:
-- The license under which the package is released.
license: LGPL-3
-- The file containing the license text.
license-file: LICENSE
-- The package author(s).
author: Sean Charles
-- An email address to which users can send suggestions, bug reports, and
-- patches.
maintainer: sean@objitsu.com
-- A copyright notice.
-- copyright:
category: Hardware Interfacing
build-type: Simple
-- Constraint on the version of Cabal needed to build this package.
cabal-version: >=1.8
executable hexwax
-- .hs or .lhs file containing the Main module.
main-is: usb1.hs
-- Modules included in this executable, other than Main.
other-modules: Hexwax
-- Other library packages from which modules are imported.
build-depends: base ==4.5.*, MissingM ==0.0.*, bytestring ==0.9.*,
vector ==0.10.*, usb ==1.2.*
--
-- This is the STEPPER MOTOR CONTROLLER program as I want to create
-- separate little utilities rather than one big monolithic command
-- line bloated application.
--
executable smc
-- .hs or .lhs file containing the Main module.
main-is: stepper.hs
-- Modules included in this executable, other than Main.
other-modules: Hexwax
-- Other library packages from which modules are imported.
build-depends: base ==4.5.*, MissingM ==0.0.*, bytestring ==0.9.*,
vector ==0.10.*, usb ==1.2.*, transformers
--
-- PULSE-WIDTH-MODULATION controller experiment... two leds on the board are
-- connected to CCP1 and CCP2, this will try to make them do something
-- interesting. executable pwm
--
executable pwm
-- .hs or .lhs file containing the Main module.
main-is: pwm.hs
-- Modules included in this executable, other than Main.
other-modules: Hexwax
-- Other library packages from which modules are imported.
build-depends: base ==4.5.*, MissingM ==0.0.*, bytestring ==0.9.*,
vector ==0.10.*, usb ==1.2.*, transformers
On 9 May 2013 16:24, harry
I've written a library, and a simple program to demonstrate it. I can write the cabal file for the library, but I can't get the executable section right. How can I tell it to use the library defined herein?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

Maybe two executables, the "third" is actually straight C... the line of
interest is "other-modules:" I guess.
Hope that helps.
Sean.
On 9 May 2013 16:38, emacstheviking
Harry,
Here is a complete cabal file for something I am working on now... it contains some libraries and three executables that use the library. It's a WIP for me BUt it works and I can even use it from Leksah by creating a workspace and adding this hexwax.cabal file as a Package.
It's long but concise!
---- -- Initial hexwax.cabal generated by cabal init. For further -- documentation, see http://haskell.org/cabal/users-guide/
-- The name of the package. name: hexwax
-- The package version. See the Haskell package versioning policy (PVP) -- for standards guiding when and how versions should be incremented. -- http://www.haskell.org/haskellwiki/Package_versioning_policy -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change version: 0.1.0.0
-- A short (one-line) description of the package. synopsis: Hexwax ExnapdIO-USB wrapper
-- A longer description of the package. -- description:
-- The license under which the package is released. license: LGPL-3
-- The file containing the license text. license-file: LICENSE
-- The package author(s). author: Sean Charles
-- An email address to which users can send suggestions, bug reports, and -- patches. maintainer: sean@objitsu.com
-- A copyright notice. -- copyright:
category: Hardware Interfacing
build-type: Simple
-- Constraint on the version of Cabal needed to build this package. cabal-version: >=1.8
executable hexwax -- .hs or .lhs file containing the Main module. main-is: usb1.hs -- Modules included in this executable, other than Main. other-modules: Hexwax -- Other library packages from which modules are imported. build-depends: base ==4.5.*, MissingM ==0.0.*, bytestring ==0.9.*, vector ==0.10.*, usb ==1.2.*
-- -- This is the STEPPER MOTOR CONTROLLER program as I want to create -- separate little utilities rather than one big monolithic command -- line bloated application. -- executable smc -- .hs or .lhs file containing the Main module. main-is: stepper.hs -- Modules included in this executable, other than Main. other-modules: Hexwax -- Other library packages from which modules are imported. build-depends: base ==4.5.*, MissingM ==0.0.*, bytestring ==0.9.*, vector ==0.10.*, usb ==1.2.*, transformers
-- -- PULSE-WIDTH-MODULATION controller experiment... two leds on the board are -- connected to CCP1 and CCP2, this will try to make them do something -- interesting. executable pwm -- executable pwm -- .hs or .lhs file containing the Main module. main-is: pwm.hs -- Modules included in this executable, other than Main. other-modules: Hexwax -- Other library packages from which modules are imported. build-depends: base ==4.5.*, MissingM ==0.0.*, bytestring ==0.9.*, vector ==0.10.*, usb ==1.2.*, transformers
On 9 May 2013 16:24, harry
wrote: I've written a library, and a simple program to demonstrate it. I can write the cabal file for the library, but I can't get the executable section right. How can I tell it to use the library defined herein?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

emacstheviking

Sorry Harry.
My bad. I got carried away at the prospect of trying to help out I guess...
you are right of course. The Hexwax.hs is *intended* to be a library but I
haven't got that far with it yet as it is still taking shape.
:(
On 9 May 2013 16:45, harry
emacstheviking
writes: ...
Where's the library definition? I could only find executables
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

You can go to hackage and check out the "package description" link
within any package page and that is just a .cabal file. Here is an
example that has both a library and an executable:
http://hackage.haskell.org/packages/archive/manatee-editor/0.1.1/manatee-edi...
On Thu, May 9, 2013 at 11:24 AM, harry
I've written a library, and a simple program to demonstrate it. I can write the cabal file for the library, but I can't get the executable section right. How can I tell it to use the library defined herein?
_______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners

David McBride
http://hackage.haskell.org/packages/archive/manatee-editor/0.1.1/manatee-edi... Thanks for the example, but it seems to work because of the simpler directory structure. I've got: src/Foo/Bar/SomeModule.hs exec/Executable.hs In Executable.hs, I have import Foo.Bar.SomeModule The library section exposes Foo.Bar.SomeModule just fine, but nothing I do will make cabal find it when compiling Executable.hs. On a related point, what actually happens to the executables defined in a cabal file?

harry
I've written a library, and a simple program to demonstrate it. I can write the cabal file for the library, but I can't get the executable section right. How can I tell it to use the library defined herein?
You need two things for this to work properly. Firstly you need to require a sufficiently recent Cabal version, for example: name: mylib version: 0.1.0 cabal-version: >= 1.10 library -- ... Secondly to avoid double-compilation you should put your program's source code in a different tree. My personal approach is to put the library's source code right within the project's root directory, but the executable's source code below a subdirectory called 'program', so the Main module is in 'program/Main.hs'. Then just mention the package itself as a dependency: executable myprog build-depends: base >= 4.5 && < 5, mylib default-language: Haskell2010 ghc-options: -W -threaded -rtsopts hs-source-dirs: program main-is: Main.hs If the program is just a demo that you wouldn't normally want to install with the library, you can make it a test suite instead of an executable: test-suite mylib-demo type: exitcode-stdio-1.0 build-depends: base >= 4.5 && < 5, mylib default-language: Haskell2010 ghc-options: -W -threaded -rtsopts hs-source-dirs: program main-is: Main.hs That way the executable is only built when you configure with --enable-tests and isn't installed together with the library. However, keep in mind that if you have an actual test suite the demo program will be run along with it when you command 'cabal test': test-suite mylib-props -- ... To avoid that just invoke your test suite on the command line instead of through 'cabal test': ln -s dist/build/tests/tests ./tests Greets, Ertugrul -- Not to be or to be and (not to be or to be and (not to be or to be and (not to be or to be and ... that is the list monad.

On Thu, May 09, 2013 at 06:10:55PM +0200, Ertugrul Söylemez wrote:
If the program is just a demo that you wouldn't normally want to install with the library, you can make it a test suite instead of an executable:
This seems like a strange hack to me. If it's not a test suite you shouldn't call it one. Instead you can use a flag which the user has to manually specify if they want the demo executables. Something like flag demo description: Install the demos. default: False manual: True executable theDemo ... if !flag(demo) buildable: False if flag(demo) build-depends: base, mylib, ... For a real-world example of this, see http://hackage.haskell.org/package/diagrams%2Dbuilder . -Brent
participants (5)
-
Brent Yorgey
-
David McBride
-
emacstheviking
-
Ertugrul Söylemez
-
harry