首页 > 解决方案 > 将依赖项添加到堆栈项目

问题描述

我对 Haskell 很陌生,我正在尝试将图形包光泽添加到我的堆栈项目中,但是在执行时遇到了问题stack build

我创建了我的堆栈项目,如下所示:

LICENSE         package.yaml        stack.yaml
README.md       package.yaml~       stack.yaml.lock
Setup.hs        project39.cabal     stack.yaml~
TAGS            project39.cabal~    test

并编辑stack.yaml和cabal文件如下:

# extra-deps:
# - acme-missiles-0.3
# - git: https://github.com/commercialhaskell/stack.git
#   commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a
# - gloss-1.13.2.1
executable project39-exe
  main-is: Main.hs
  other-modules:
      Paths_project39
  hs-source-dirs:
      app
  ghc-options: -threaded -rtsopts -with-rtsopts=-N
  build-depends:
      base >=4.7 && <5
    , project39
    , gloss
  default-language: Haskell2010

srcLib.hs 文件中,我添加了一个Import Graphics.Gloss来测试它是否有效:

module Lib
    ( someFunc
    ) where
import Graphics.Gloss

但是当我这样做时,stack build我收到以下错误:

    Could not load module ‘Graphics.Gloss’
    It is a member of the hidden package ‘gloss-1.13.2.1’.
    Perhaps you need to add ‘gloss’ to the build-depends in your .cabal file.
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
4 | import Graphics.Gloss
  | ^^^^^^^^^^^^^^^^^^^^^

我不确定这里的问题是什么以及如何解决它。

标签: haskellhaskell-stack

解决方案


您的 package.yaml 中有一个单独的library节。您需要在gloss此处添加依赖项。


推荐阅读