构建一个简单的教程项目时出现cabal错误

时间:2016-05-10 21:09:55

标签: haskell cabal cabal-install

1问题

我正在关注您构建项目haq的教程How to Write a Haskell Program

每当我尝试运行cabal test时,我都会收到以下错误代码:

<command line>: cannot satisfy -package-id haq-0.1.0.0-inplace
    (use -v for more information)
    cabal: Error: some packages failed to install:
    haq-0.1.0.0 failed during the building phase. The exception was:
    ExitFailure 1

请注意,它无法构建的包本身(至少我认为这个错误意味着什么)。

2详情

2.1完整错误

$ cabal install --enable-tests
Resolving dependencies...
Configuring haq-0.1.0.0...
Building haq-0.1.0.0...
Failed to install haq-0.1.0.0
Build log ( /home/user/.cabal/logs/haq-0.1.0.0.log ):
Configuring haq-0.1.0.0...
Warning: The 'license-file' field refers to the file 'LICENSE' which does not
exist.
Building haq-0.1.0.0...
Preprocessing executable 'haq' for haq-0.1.0.0...
[1 of 1] Compiling Main             ( Haq.hs, dist/build/haq/haq-tmp/Main.o )
Linking dist/build/haq/haq ...
Preprocessing test suite 'tests' for haq-0.1.0.0...
<command line>: cannot satisfy -package-id haq-0.1.0.0-inplace
    (use -v for more information)
    cabal: Error: some packages failed to install:
    haq-0.1.0.0 failed during the building phase. The exception was:
    ExitFailure 1

2.2项目文件结构

.
├── .cabal-sandbox
├── cabal.sandbox.config
├── dist
├── haq.cabal
├── Haq.hs
├── HSpecTests.hs
└── Setup.hs

2.3 Haq.hs

    --
    -- Copyright (c) 2006 Don Stewart - http://www.cse.unsw.edu.au/~dons/
    -- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html)
    --
    import System.Environment

    -- | 'main' runs the main program
    main :: IO ()
    main = getArgs >>= print . haqify . head

    haqify s = "Haq! " ++ s

2.4 haq.cabal

    -- Initial haq.cabal generated by cabal init.  For further documentation, 
    -- see http://haskell.org/cabal/users-guide/

    name:                haq
    version:             0.1.0.0
    -- synopsis:            
    -- description:         
    -- license:             
    license-file:        LICENSE
    author:              First Last
    maintainer:          first.last@gmail.com
    -- copyright:           
    -- category:            
    build-type:          Simple
    -- extra-source-files:  
    cabal-version:       >=1.10

    executable haq
        main-is:             Haq.hs
        -- other-modules:       
        -- other-extensions:    
        build-depends:       base >=4.8 && <4.9
        -- hs-source-dirs:      
        default-language:    Haskell2010

    test-suite tests
        ghc-options: -Wall
        default-extensions:  OverloadedStrings
        type: exitcode-stdio-1.0
        main-is: HSpecTests.hs
        build-depends:       base,
                                                 haq,
                                                 hspec                >= 1.8
        default-language:    Haskell2010

2.5 HSpecTests.hs

    module Main where

    import Haq
    import Test.Hspec

    main :: IO ()
    main = hspec $ do

        describe "Validate haqify function" $ do
            it "haqify is supposed to prefix Haq! to things" $ do
                haqify "me" `shouldBe` "Haq! me"

1 个答案:

答案 0 :(得分:3)

更新

运行cabal test时出现错误。

问题是您的测试套件依赖于库haq,但cabal文件不会声明库组件。它只声明一个可执行文件。

修复:

  1. 将现有文件Haq.hs重命名为App.hs。适当更新cabal文件。
  2. 使用以下内容创建一个新文件'Haq.hs`:

    module Haq (haqify) where
    
    haqify :: String -> String
    haqify s = "Haqify! " ++ s
    
  3. 将此节添加到cabal文件中:

    library
      build-depends: base >= 4.8 && < 4.9
      exposed-modules: Haq
    
  4. 运行cabal buildcabal test

  5. 原始答案

    我修复cabal build中的缩进问题后,我能够Haq.hs您的项目:

    • 删除了main
    • 行上的前导空格
    • 删除了haqify
    • 前面的前导空格