第一次尝试使用 Cabal 的依赖

First time attempting to use dependency with Cabal

运行 本地 SparkSetup 文件夹中的初始化命令:

cabal init

这将创建以下文件:

SparkSetup.cabal :

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

name:                SparkSetup
version:             0.1.0.0
-- synopsis:            
-- description:         
-- license:             
license-file:        LICENSE
author:              user
maintainer:          user
-- copyright:           
-- category:            
build-type:          Simple
-- extra-source-files:  
cabal-version:       >=1.10

executable SparkSetup
  -- main-is:             
  -- other-modules:       
  -- other-extensions:    
  build-depends:       base >=4.7 && <4.8
  -- hs-source-dirs:      
  default-language:    Haskell2010

Setup.hs :

import Distribution.Simple
main = defaultMain

然后我修改我的 Setup.hs 文件以包含来自 https://hackage.haskell.org/package/download

的 Network.Download 模块

Setup.hs :

import Network.Download
import Distribution.Simple
main = defaultMain

然后 运行 命令:

cabal sandbox init
cabal install -j

但是收到错误:

Resolving dependencies...
Notice: installing into a sandbox located at C:\Users\Users\Google
Drive\SparkSetup\.cabal-sandbox
Configuring SparkSetup-0.1.0.0...
Failed to install SparkSetup-0.1.0.0
Last 10 lines of the build log ( C:\Users\users\Google Drive\SparkSetup\.cabal-
sandbox\logs\SparkSetup-0.1.0.0.log ):
Configuring SparkSetup-0.1.0.0...
setup-Cabal-1.18.1.3-x86_64-windows-ghc-7.8.3.exe: No 'main-is' field found
for executable SparkSetup
cabal: Error: some packages failed to install:
SparkSetup-0.1.0.0 failed during the configure step. The exception was:
ExitFailure 1

如何在我的项目中包含下载包 (https://hackage.haskell.org/package/download)?

更新:

SparkSetup.cabal :

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

name:                SparkSetup
version:             0.1.0.0
-- synopsis:            
-- description:         
-- license:             
license-file:        LICENSE
author:              user
maintainer:          user
-- copyright:           
-- category:            
build-type:          Simple
-- extra-source-files:  
cabal-version:       >=1.10

executable SparkSetup
  main-is: SparkSetup.hs  
  -- other-modules:       
  -- other-extensions:    
  build-depends:       base >=4.7 && <4.8, download
  -- hs-source-dirs:      
  default-language:    Haskell2010

火花Setup.hs :

main = putStrLn "Hello, World!"

运行 cabal install

给出错误:

setup-Cabal-1.18.1.3-x86_64-windows-ghc-7.8.3.exe: Bad header file: download.h
The header file contains a compile error. You can re-run configure with the
verbosity flag -v3 to see the error messages from the C compiler.
cabal: Error: some packages failed to install:
SparkSetup-0.1.0.0 depends on download-0.3.2 which failed to install.
download-0.3.2 failed during the configure step. The exception was:
ExitFailure 1

更新 2:

C:\Users\Adrian\Google Drive\SparkSetup>cabal install -v3
Using a sandbox located at C:\Users\Adrian\Google
Drive\SparkSetup\.cabal-sandbox
Searching for ghc in path.
Found ghc at C:\Program Files\Haskell Platform14.2.0.0\bin\ghc.exe
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc.exe",["--numeric-ver
sion"])
C:\Program Files\Haskell Platform14.2.0.0\bin\ghc.exe is version 7.8.3
looking for tool ghc-pkg near compiler in C:\Program Files\Haskell
Platform14.2.0.0\bin
found ghc-pkg in C:\Program Files\Haskell Platform14.2.0.0\bin\ghc-pkg.exe
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc-pkg.exe",["--version
"])
C:\Program Files\Haskell Platform14.2.0.0\bin\ghc-pkg.exe is version 7.8.3
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc.exe",["--supported-l
anguages"])
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc.exe",["--info"])
The package database already exists: C:\Users\Adrian\Google
Drive\SparkSetup\.cabal-sandbox\x86_64-windows-ghc-7.8.3-packages.conf.d
Reading available packages...
Reading available packages...
Reading installed packages...
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc-pkg.exe",["dump","--
package-db=C:\Users\Adrian\Google Drive\SparkSetup\.cabal-sandbox\x86_64-w
indows-ghc-7.8.3-packages.conf.d","-v0"])
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc.exe",["--print-libdi
r"])
Reading installed packages...
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc-pkg.exe",["dump","--
global","-v0"])
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc-pkg.exe",["dump","--
package-db=C:\Users\Adrian\Google Drive\SparkSetup\.cabal-sandbox\x86_64-w
indows-ghc-7.8.3-packages.conf.d","-v0"])
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc.exe",["--print-libdi
r"])
Reading available packages...
Choosing modular solver.
Resolving dependencies...
[__0] trying: feed-0.3.9.7/installed-4ff... (user goal)
[__1] trying: base-4.7.0.1/installed-7c4... (dependency of feed-0.3.9.7/installe
d-4ff...)
[__2] trying: rts-1.0/installedbuil... (dependency of base-4.7.0.1/installed-7c4
...)
[__3] trying: integer-gmp-0.5.1.0/installed-d42... (dependency of base-4.7.0.1/i
nstalled-7c4...)
[__4] trying: ghc-prim-0.3.1.0/installed-95d... (dependency of base-4.7.0.1/inst
alled-7c4...)
[__5] trying: time-1.4.2/installed-102... (dependency of feed-0.3.9.7/installed-
4ff...)
[__6] trying: deepseq-1.3.0.2/installed-7fa... (dependency of time-1.4.2/install
ed-102...)
[__7] trying: array-0.5.0.0/installed-a62... (dependency of deepseq-1.3.0.2/inst
alled-7fa...)
[__8] trying: Win32-2.3.0.2/installed-698... (dependency of time-1.4.2/installed
-102...)
[__9] trying: bytestring-0.10.4.0/installed-016... (dependency of Win32-2.3.0.2/
installed-698...)
[_10] trying: old-time-1.1.0.2/installed-a22... (dependency of feed-0.3.9.7/inst
alled-4ff...)
[_11] trying: old-locale-1.0.0.6/installed-09b... (dependency of feed-0.3.9.7/in
stalled-4ff...)
[_12] trying: tagsoup-0.13.3/installed-d1b... (user goal)
[_13] trying: text-1.1.0.0/installed-1ba... (dependency of tagsoup-0.13.3/instal
led-d1b...)
[_14] trying: containers-0.5.5.1/installed-080... (dependency of tagsoup-0.13.3/
installed-d1b...)
[_15] trying: time-locale-compat-0.1.1.0/installed-712... (user goal)
[_16] trying: utf8-string-1/installed-8df... (user goal)
[_17] trying: xml-1.3.14/installed-97a... (user goal)
[_18] trying: SparkSetup-0.1.0.0 (user goal)
[_19] next goal: download (dependency of SparkSetup-0.1.0.0)
[_19] trying: download-0.3.2
[_20] done
Notice: installing into a sandbox located at C:\Users\Adrian\Google
Drive\SparkSetup\.cabal-sandbox
Ready to install download-0.3.2
Extracting
C:\Users\Adrian\AppData\Roaming\cabal\packages\hackage.haskell.org\download[=19=].3.
2\download-0.3.2.tar.gz
Waiting for install task to finish...
to C:\Users\Adrian\AppData\Local\Temp\download-0.3.2-1540...
Updating download.cabal with the latest revision from the index.
Configuring download-0.3.2...
Using external setup method with build-type Simple
creating
C:\Users\Adrian\AppData\Local\Temp\download-0.3.2-1540\download-0.3.2\dist\dist-
sandbox-8472864c\setup
creating
C:\Users\Adrian\AppData\Local\Temp\download-0.3.2-1540\download-0.3.2\dist\dist-
sandbox-8472864c
creating
C:\Users\Adrian\AppData\Local\Temp\download-0.3.2-1540\download-0.3.2\dist
creating
C:\Users\Adrian\AppData\Local\Temp\download-0.3.2-1540\download-0.3.2\dist\dist-
sandbox-8472864c
creating
C:\Users\Adrian\AppData\Local\Temp\download-0.3.2-1540\download-0.3.2\dist\dist-
sandbox-8472864c\setup
Reading installed packages...
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc-pkg.exe",["dump","--
global","-v0"])
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc-pkg.exe",["dump","--
user","-v0"])
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc-pkg.exe",["dump","--
package-db=C:\Users\Adrian\Google Drive\SparkSetup\.cabal-sandbox\x86_64-w
indows-ghc-7.8.3-packages.conf.d","-v0"])
("C:\Program Files\Haskell Platform\2014.2.0.0\bin\ghc.exe",["--print-libdi
r"])
Using Cabal library version 1.18.1.3
Using
C:\Users\Adrian\AppData\Local\Temp\download-0.3.2-1540\download-0.3.2\dist/dist-
sandbox-8472864c\setup\setup.hs
as setup script.
Found cached setup executable:
C:\Users\Adrian\AppData\Roaming\cabal\setup-exe-cache\setup-Cabal-1.18.1.3-x86_6
4-windows-ghc-7.8.3.exe
C:\Users\Adrian\AppData\Roaming\cabal\setup-exe-cache\setup-Cabal-1.18.1.3-x86_6
4-windows-ghc-7.8.3.exe
configure --verbose=3 --builddir=dist/dist-sandbox-8472864c --ghc
--prefix=C:\Users\Adrian\Google Drive\SparkSetup\.cabal-sandbox
--bindir=C:\Users\Adrian\Google Drive\SparkSetup\.cabal-sandbox\bin
--libdir=C:\Users\Adrian\Google Drive\SparkSetup\.cabal-sandbox
--libsubdir=x86_64-windows-ghc-7.8.3\download-0.3.2
--libexecdir=C:\Users\Adrian\Google
Drive\SparkSetup\.cabal-sandbox\download-0.3.2
--datadir=C:\Users\Adrian\Google Drive\SparkSetup\.cabal-sandbox
--datasubdir=x86_64-windows-ghc-7.8.3\download-0.3.2
--docdir=C:\Users\Adrian\Google
Drive\SparkSetup\.cabal-sandbox\doc\x86_64-windows-ghc-7.8.3\download-0.3.2
--htmldir=C:\Users\Adrian\Google
Drive\SparkSetup\.cabal-sandbox\doc\x86_64-windows-ghc-7.8.3\download-0.3.2\html

--haddockdir=C:\Users\Adrian\Google
Drive\SparkSetup\.cabal-sandbox\doc\x86_64-windows-ghc-7.8.3\download-0.3.2\html

--sysconfdir=C:\Users\Adrian\Google Drive\SparkSetup\.cabal-sandbox\etc
--global --package-db=C:\Users\Adrian\Google
Drive\SparkSetup\.cabal-sandbox\x86_64-windows-ghc-7.8.3-packages.conf.d
--extra-prog-path=C:\Users\Adrian\AppData\Roaming\cabal\bin --constraint=xml
==1.3.14 --constraint=tagsoup ==0.13.3 --constraint=feed ==0.3.9.7
--constraint=bytestring ==0.10.4.0 --constraint=base ==4.7.0.1 --disable-tests
--disable-benchmarks
Redirecting build log to {handle: C:\Users\Adrian\Google
Drive\SparkSetup\.cabal-sandbox\logs\download-0.3.2.log}
Failed to install download-0.3.2
Last 10 lines of the build log ( C:\Users\Adrian\Google Drive\SparkSetup\.cabal-
sandbox\logs\download-0.3.2.log ):
function)
cbits/download.h:90:1: error: unknown type name '__BEGIN_DECLS'
cbits/download.h:93:6: error: expected '=', ',', ';', 'asm' or '__attribute__'
before '*' token
cbits/download.h:124:1: error: expected '=', ',', ';', 'asm' or
'__attribute__' before 'typedef'
cbits/download.h:125:1: error: unknown type name 'auth_t'
setup-Cabal-1.18.1.3-x86_64-windows-ghc-7.8.3.exe: Bad header file: download.h
The header file contains a compile error. You can re-run configure with the
verbosity flag -v3 to see the error messages from the C compiler.
cabal: Error: some packages failed to install:
SparkSetup-0.1.0.0 depends on download-0.3.2 which failed to install.
download-0.3.2 failed during the configure step. The exception was:
ExitFailure 1

你通常根本不碰 Setup.hs

而是将 download 添加到 .cabal 文件中的 build-depends 字段。

此外,.cabal 文件不完整:取消注释 main-is 字段并输入主模块的文件名,例如

main-is: SparkSetup.hs