mb14
mb14

Reputation: 22596

Can you have an executable and library in the same cabal package

I'm new using cabal and I need my package to include a small executable as well as the whole library. Is it possible to do so (to export an executable AND a library) or does a cabal package have a type (executable OR binary). Is it also possible to export many executable in the same packagke ?

Upvotes: 2

Views: 1968

Answers (1)

Nicolas
Nicolas

Reputation: 24759

Yes you can. For example, here is the corresponding excerpt of the HaskellStarter project, that I highly recommend:

-- configuration for building a library
library
  hs-source-dirs: src
  exposed-modules:
    HaskellStarter.CommitPrinter
  other-modules:
    HaskellStarter.Util
  build-depends:
    base >= 4 && < 5,
    github >= 0.7.4 && < 0.8

-- configuration for an executable
executable githubCommitPrinter
  hs-source-dirs: executables
  main-is: Main.hs
  build-depends:
    base >= 4 && < 5,
    haskell-starter

Notice how the library is reused in the executable dependencies.

Upvotes: 12

Related Questions