【问题标题】:Stack build fails due to missing package although stack ghci works尽管堆栈 ghci 有效,但由于缺少软件包,堆栈构建失败
【发布时间】:2016-02-25 08:21:09
【问题描述】:

我正在尝试使用堆栈在 Haskell 中构建一个简单的程序。我使用stack new 创建了一个新项目,然后做了一个stack setup。模板构建良好。

我想尝试二进制文件解析,所以我导入了Data.ByteString。我在 cabal 文件中的build-depends 如下所示:

build-depends:     base >= 4.7 && < 5
                 , bytestring >= 0.10.6
                 , binary >= 0.7.5

stack ghci 现在可以正常工作,但stack build 仍然不开心。 谁能告诉我我在这里做错了什么?

这是完整的错误信息:

test-0.1.0.0: build
Preprocessing library test-0.1.0.0...
In-place registering test-0.1.0.0...
Preprocessing executable 'test-exe' for test-0.1.0.0...

haskell/test/app/Main.hs:4:18:
    Could not find module ‘Data.ByteString’
    It is a member of the hidden package ‘bytestring-0.10.6.0@bytes_6VWy06pWzJq9evDvK2d4w6’.
    Perhaps you need to add ‘bytestring’ to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

haskell/test/app/Main.hs:5:8:
    Could not find module ‘Data.Binary.Get’
    It is a member of the hidden package ‘binary-0.7.5.0@binar_3uXFWMoAGBg0xKP9MHKRwi’.
    Perhaps you need to add ‘binary’ to the build-depends in your .cabal file.
    Use -v to see a list of the files searched for.

--  While building package test-0.1.0.0 using:
      .stack/setup-exe-cache/x86_64-osx/setup-Simple-Cabal-1.22.5.0-ghc-7.10.3 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.22.5.0 build lib:test exe:test-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1

这是我的 app/Main.hs 文件:

module Main where

import Lib
import qualified Data.ByteString as B
import Data.Binary.Get
import Data.Word

main :: IO ()
main =  do
    putStrLn "f"

非常感谢您的帮助。

【问题讨论】:

  • stack build 在抱怨什么?
  • 找不到模块“Data.ByteString”它是隐藏包“bytestring-0.10.6.0@bytes_6VWy06pWzJq9evDvK2d4w6”的成员。也许您需要在 .cabal 文件中的 build-depends 中添加“bytestring”。使用 -v 查看搜索的文件列表。找不到模块“Data.Binary.Get”它是隐藏包“binary-0.7.5.0@binar_3uXFWMoAGBg0xKP9MHKRwi”的成员。也许您需要在 .cabal 文件中的 build-depends 中添加“二进制”。使用 -v 查看搜索的文件列表。
  • 对不起。我不知道如何在评论中格式化
  • @draetsch:首先,您可以随时edit 您的问题包含新信息。其次,添加您的 cabal 文件的完整内容(减去个人信息,但应包括 library/executable/benchmark/test-suite 部分)。第三,发布确切的错误消息,包括发生问题的行和文件。你很可能在你的可执行文件中使用ByteString
  • 你更新你的stack.yaml了吗

标签: haskell cabal haskell-stack


【解决方案1】:

这可能是因为您将bytestring 添加到库的build-depends,而不是可执行文件。避免需要为不同节重复这些依赖关系的一种选择是使用hpack 作为包描述格式。

【讨论】:

  • 感谢您的回答。正如我在上一条评论中已经说过的那样,这确实是错误。谢谢你指点我打包。我会看的。
猜你喜欢
  • 2020-10-23
  • 2018-11-28
  • 2021-01-16
  • 2021-05-02
  • 1970-01-01
  • 2015-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多