【问题标题】:Executable within a library and while using the same library in cabal可在库中执行,同时在 cabal 中使用相同的库
【发布时间】:2015-08-25 23:11:06
【问题描述】:

这是我第一次尝试开源项目,但我仍然无法找到正确的方法来设置我的 .cabal 文件。

我有库、可执行文件和(即将推出)测试配置。 我想在可执行文件中使用该库,因此下载后两者都可以使用。

我关注了这个guide,但我仍然在为 cabal-config 苦苦挣扎,因为我只能在再次导入所有内容时让它工作。

我的当前目录

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

可执行的 Main.hs 头文件如下所示。

module Main where

import Format.C
import Format.Converter

Format/ 中的库文件如下所示。

module Format.{filename} where
...

这就是 cabal 文件的样子。

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:
...

如果没有注释,当我cabal build 时出现此错误。

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

它现在可以工作,但在教程中,可执行文件使用的是同一个 cabal 文件中的库。

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

我知道这目前有效,但我宁愿从一开始就以正确的方式使用它。这是“正确”的方式吗?

【问题讨论】:

  • UTFConverter cabal 文件顶部的 version: 行是什么?如果您只是省略UTFConverter 的边界检查,它是否有效?
  • @user5402: 0.1.0.0.

标签: haskell packages cabal


【解决方案1】:

这是因为您的库版本是 0.1.0.0,而不是 0.1。它们并不完全匹配,因此 cabal 不会将您的图书馆视为候选人。相反,请使用 0.1.*0.1.0.0,具体取决于您的版本策略:

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

参考文献

【讨论】:

    猜你喜欢
    • 2014-07-22
    • 2014-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多