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

时间:2016-02-25 08:21:09

标签: haskell cabal haskell-stack

我正在尝试使用堆栈在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 个答案:

答案 0 :(得分:4)

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