1
votes

I have my foo.cabal file looking like this:

library
  exposed-modules:
      Foo.Bar,
      Foo.Something
  hs-source-dirs:      lib
  default-language:    Haskell2010

executable foobar
  main-is:             Main.hs
  other-modules:
      Utils,  -- Local module in ./src
      Foo.Bar

  hs-source-dirs:      src
  default-language:    Haskell2010

According to the sample code here: https://www.haskell.org/cabal/users-guide/developing-packages.html#example-a-package-containing-a-library-and-executable-programs

And I get the following error:

$ cabal build
Resolving dependencies...
Configuring foobar-0.1.0.0...
Preprocessing executable 'foobar' for foobar-0.1.0.0..
cabal: can't find source for Foo/Bar in src, dist/build/foobar/autogen,
dist/build/global-autogen
2

2 Answers

1
votes

Add the line build-depends: foo to your executable stanza to indicate the executable depends on the library you're defining.

0
votes

You'll have to add the library to the dependencies of the executable. Here's the hpack version of your cabal file, I can never remember the cabal syntax:

name: foo
version: 0.1.0
dependencies:
  - base

source-dirs: lib

# no need for exponsed-modules, hpack does that for you

executable:
  main: Main.hs
  source-dirs: src
  dependencies:
    - base
    - foo

Or just use stack new, and you get a working project.