我正在尝试构建一个使用 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
这种意外的行为.
最佳答案
确保 package.yaml
存在于项目目录的根目录中。
package.yaml
是一种新的文件格式,用于改进 cabal 的语法,由 hpack 转换。 .
Stack 对 hpack 的支持与 stack build
命令一样强大,可以使用 hpack
命令自动将 package.yaml 转换为 cabal 文件。
因此,删除 package.yaml
或编辑 package.yaml
以添加 Euterpea 包。
编辑它不会那么困难,因为它的格式是 YAML。
关于haskell - 为什么 `stack build` 会改变我的 .cabal 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47724988/