2017-05-27 113 views
1

运行后:添加依赖项来堆栈项目?

stack new my-project 
cd my-project 
stack setup 
stack build 

我想给Conduit库添加作为一个依赖。

我编辑所产生的,通过stack newstack.yaml有:

extra-deps: 
- conduit-1.2.10 

然后,我修改了my-project.cabal从:

executable my-project-exe 
    hs-source-dirs:  app 
    main-is:    Main.hs 
    ghc-options:   -threaded -rtsopts -with-rtsopts=-N 
    build-depends:  base 
        , my-project 
    default-language: Haskell2010 

到:

executable my-project-exe 
    hs-source-dirs:  app 
    main-is:    Main.hs 
    ghc-options:   -threaded -rtsopts -with-rtsopts=-N 
    build-depends:  base 
        , my-project 
        , conduit 
    default-language: Haskell2010 

当尝试到stack build以下:

$cat app/Main.hs 

module Main where 

import Conduit 
import Lib 

main :: IO() 
main = someFunc 

它失败:

$stack build 
mtl-2.2.1: using precompiled package 
primitive-0.6.1.0: using precompiled package 
stm-2.4.4.1: using precompiled package 
transformers-compat-0.5.1.4: using precompiled package 
exceptions-0.8.3: using precompiled package 
mmorph-1.0.9: using precompiled package 
transformers-base-0.4.4: using precompiled package 
monad-control-1.0.1.0: using precompiled package 
lifted-base-0.2.3.10: using precompiled package 
resourcet-1.1.9: using precompiled package 
conduit-1.2.10: configure 
conduit-1.2.10: build 
conduit-1.2.10: copy/register 
my-project-0.1.0.0: configure (lib + exe) 
Configuring my-project-0.1.0.0... 
my-project-0.1.0.0: build (lib + exe) 
Preprocessing library my-project-0.1.0.0... 
[1 of 1] Compiling Lib    (src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/Lib.o) 
Preprocessing executable 'my-project-exe' for my-project-0.1.0.0... 
[1 of 1] Compiling Main    (app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-1.24.2.0/build/my-project-exe/my-project-exe-tmp/Main.o) 

/Users/kevinmeredith/Workspace/conduit_sandbox/my-project/app/Main.hs:3:1: error: 
    Failed to load interface for ‘Conduit’ 
    Use -v to see a list of the files searched for. 
Completed 12 action(s). 

-- While building package my-project-0.1.0.0 using: 
     /Users/kevinmeredith/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-1.24.2.0 build lib:my-project exe:my-project-exe --ghc-options " -ddump-hi -ddump-to-file" 
    Process exited with code: ExitFailure 1 

我怎样才能正确地添加conduit

将库添加到stack项目时,是否需要编辑stack.yaml和/或my-project.cabal

回答

2

如果你看看haddocks for conduit,注意你要导入的模块不是Conduit,它是Data.Conduit

Conduit模块来自conduit-combinators包。如果这是你想改用包,如下调整你的阴谋文件之前import Conduit为:

executable my-project-exe 
    hs-source-dirs:  app 
    main-is:    Main.hs 
    ghc-options:   -threaded -rtsopts -with-rtsopts=-N 
    build-depends:  base 
        , my-project 
        , conduit-combinators 
    default-language: Haskell2010 

包之间的区别总结如下(这是从the project's readme拍摄)。

  • conduit-combinators:提供在内置
  • conduit大量的常见功能:定义了核心数据类型和原语功能
  • conduit-extra:增加了对许多常见的低级操作

支持附注:您不需要对stack.yaml文件进行任何更改,因为这两个软件包均可在堆栈中使用。

+0

谢谢,@Erik。如果'conduit-libraries'不在堆栈中,那么我需要对我的'stack.yaml'做些什么? –

+0

如果您想要编辑stack.yaml,例如,需要依赖本地软件包,可用于hackage而非堆栈的软件包,位于git repo中的软件包等。有关如何执行此操作的具体详细信息,请参阅https://docs.haskellstack.org/en/stable/GUIDE/#adding-dependencies – Erik

+0

但是,您在原始问题中是否正确。要取消它,只需在extra-deps字段中列出软件包名称,堆栈应该为您下载它。 – Erik

相关问题