首页 文章

尽管stack ghci工作,但由于缺少包,堆栈构建失败

提问于
浏览
2

我正在尝试使用堆栈在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"

非常感谢您的帮助 .

1 回答

  • 4

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

相关问题