Cirquit
Cirquit

Reputation: 464

Executable within a library and while using the same library in cabal

This is my first try at an open source project, but I still can't get the right way to set up my .cabal file.

I have have library, an executable and a (soon to come) test config. I want to use the library and within the executable, so the both of them can be used when it gets downloaded.

I followed this guide, but I'm still struggling with the cabal-config as I only get it to work while importing everything again.

My current directory

- src/
    - Main.hs
    - Format/
          - C.hs
          - Converter.hs
          - Raw.hs
          - RGB565.hs
- tests/...
- dist/...
- UTFTConverter.cabal

The executable Main.hs header looks like this.

module Main where

import Format.C
import Format.Converter

The library files in Format/ look like this.

module Format.{filename} where
...

This is what the cabal file looks like.

name:          UTFTConverter
...
cabal-version: >=1.10

library
exposed-modules:   Format.C
                 , Format.Converter
                 , Format.Raw
                 , Format.RGB565
build-depends:     base        >=4.7  && <4.8
                 , filepath    >=1.3  && <1.4
                 , directory   >=1.2  && <1.3
                 , time        >=1.4  && <1.5
                 , bytestring  >=0.10 && <0.11
                 , JuicyPixels >=3.2  && <3.3
hs-source-dirs:  src
...

executable UTFTConverter
main-is:         Main.hs
build-depends:     base             >=4.7  && <4.8
                 , filepath         >=1.3  && <1.4
                 , directory        >=1.2  && <1.3
                 , time             >=1.4  && <1.5
                 , bytestring       >=0.10 && <0.11
                 , JuicyPixels      >=3.2  && <3.3
               --, UTFTConverter    ==0.1    <-- this does not work
hs-source-dirs:  src
...

test-suite tests:
...

Without the comment this error comes up when I cabal build.

...
cabal: At least the following dependencies are missing:
UTFTConverter ==0.1
...

It works right now, but in the tutorial the executable was using the library in the same cabal file.

executable bassbull
main-is:             Main.hs
ghc-options:         -rtsopts -O2
build-depends:       base,
                     bassbull,    -- <-- this is the name of the library
                     bytestring,
                     cassava
hs-source-dirs:      src
default-language:    Haskell2010

I know this is currently working, but I would rather use it the right way from the start. Is this the "right" way?

Upvotes: 2

Views: 177

Answers (1)

Zeta
Zeta

Reputation: 105876

That's due to your library version being 0.1.0.0, not 0.1. They don't match up exactly, thus cabal doesn't recognize your library as a candidate. Instead, use 0.1.* or 0.1.0.0 depending on your version policy:

executable UTFTConverter
main-is:         Main.hs
build-depends:     base             >=4.7  && <4.8
                 , filepath         >=1.3  && <1.4
                 , directory        >=1.2  && <1.3
                 , time             >=1.4  && <1.5
                 , bytestring       >=0.10 && <0.11
                 , JuicyPixels      >=3.2  && <3.3
                 , UTFTConverter    ==0.1.0.0
hs-source-dirs:  src

References

Upvotes: 1

Related Questions