9

我正在尝试构建一个使用Euterpea的项目。

运行stack build时出现以下错误,提示我需要添加Euterpea到文件的build-depends部分.cabal

$ sb
composition-0.1.0.0: build (lib + exe)
Preprocessing library composition-0.1.0.0...
[2 of 2] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-linux-nix/Cabal-1.24.2.0/build/Lib.o )

/home/matthew/backup/composition/composition/src/Lib.hs:5:1: error:
    Failed to load interface for ‘Euterpea’
    It is a member of the hidden package ‘Euterpea-2.0.4’.
    Perhaps you need to add ‘Euterpea’ to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

--  While building package composition-0.1.0.0 using:
      /home/matthew/.stack/setup-exe-cache/x86_64-linux-nix/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-linux-nix/Cabal-1.24.2.0 build lib:composition exe:composition-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

我在Euterpea那里添加,然后library我的.cabal文件部分如下。

library
  hs-source-dirs:
      src
  build-depends:   base >= 4.7 && < 5
                 , Euterpea
  exposed-modules:
      Lib
  other-modules:
      Paths_composition
  default-language: Haskell2010

但是,当我再次运行stack build时,它给出了相同的错误 - 并将我的.cabal文件更改回原来的样子,library然后该部分看起来像

library
  hs-source-dirs:
      src
  build-depends:
      base >= 4.7 && < 5
  exposed-modules:
      Lib
  other-modules:
      Paths_composition
  default-language: Haskell2010

为什么要stack build更改我的cabal文件?我以前从未见过这种情况发生。


旁注:不确定它是否相关,但.cabal文件的格式似乎与通常不同。与以前的项目一样,我通过运行自动初始化stack new <project-name>。我不知道我可能做了什么与以前的项目不同导致stack build.

4

2 回答 2

14

确保package.yaml存在于项目目录的根目录中。

package.yaml是一种改进 cabal 语法的新文件格式,由hpack转换。

Stack 对 hpack 的支持与stack build命令自动将 package.yaml 转换为带有hpack命令的 cabal 文件一样强大。

因此,删除package.yaml或编辑package.yaml以添加 Euterpea 包。编辑它不会那么困难,因为它的格式是 YAML。

于 2017-12-09T04:06:34.630 回答
1

我想补充YAMAMOTO Yuji 的答案。解决方案是绝对正确的。但我只是想添加一些东西,编辑package.yaml.

第 1 步:最棘手的部分是找到正确的包名称

使用HoogleStackage查找模块所在的包。在这篇文章中阅读更多关于如何查找包名的信息。

第 2 步:现在您必须打开 package.yaml 文件并添加包名。在您的情况下,在依赖项列表中添加“Euterpea”包。

dependencies:
...
- your-package-name

请注意,必须以不同的方式添加Euterpea包。请阅读这篇文章以获得更好的理解。

第 3 步:在项目根目录中打开project-name.cabal并在下面添加所需的包名称build-depends

library
  hs-source-dirs:
      src

  build-depends:
      base >= 4.7 && < 5
    , your-package-name

  exposed-modules:
      Lib

第 4 步stack build下载和构建依赖项的问题(或者stack ghci如果您计划在REPL中使用它)

希望这有效!快乐编码!:)

于 2021-01-20T00:53:54.430 回答