【发布时间】:2016-03-11 18:07:05
【问题描述】:
我在 (X)Ubuntu 15.10 上使用 Haskell 版本 7.8.4,Cabal-Install 1.18 都通过 apt 安装。我没有尝试在这台机器上手动安装任何与 Haskell 相关的东西。我设置了一个 cabal 沙箱,获取并安装了一个模块,却发现 ghc 似乎没有收到它。 ghc -v 似乎暗示我有两个版本的 cabal 库,它们相互影响。这是如何工作的?
我从一个空目录开始/tmp/haskell-example
然后我做一个cabal sandbox init。
$ cabal sandbox init
Writing a default package environment file to
/tmp/haskell-example/cabal.sandbox.config
Creating a new sandbox at /tmp/haskell-example/.cabal-sandbox
然后我安装natural-numbers,因为我想在程序中使用Data.Natural 模块。此操作成功。
$ cabal install natural-numbers
Resolving dependencies...
Notice: installing into a sandbox located at
/tmp/haskell-example/.cabal-sandbox
Configuring natural-numbers-0.1.2.0...
Building natural-numbers-0.1.2.0...
Installed natural-numbers-0.1.2.0
我可以验证 Data.Natural 模块确实已安装到 cabal 沙箱中。
$ ls /tmp/haskell-example/.cabal-sandbox/lib/x86_64-linux-ghc-7.8.4/natural-numbers-0.1.2.0
Data
libHSnatural-numbers-0.1.2.0.a
libHSnatural-numbers-0.1.2.0-ghc7.8.4.so
$ ls /tmp/haskell-example/.cabal-sandbox/lib/x86_64-linux-ghc-7.8.4/natural-numbers-0.1.2.0/Data
Natural.dyn_hi
Natural.hi
然后我创建一个简单的Main.hs 文件,该文件导入Data.Natural 但不使用它。
module Main where
import Data.Natural
main = putStrLn "Hello World"
当我尝试ghc Main.hs 时,我看到以下内容:
$ ghc Main.hs
Main.hs:3:8:
Could not find module ‘Data.Natural’
Use -v to see a list of the files searched for.
启用详细标志后,我的阴谋集团似乎被后来的阴谋集团所掩盖,而后者又反过来影响了早期的阴谋集团。为什么会这样?
$ ghc -v Main.hs
Glasgow Haskell Compiler, Version 7.8.4, stage 2 booted by GHC version 7.8.4
Using binary package database: /usr/lib/ghc/package.conf.d/package.cache
hiding package Cabal-1.18.1.5 to avoid conflict with later version Cabal-1.22.1.1
wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-ec14d2f6075975a2ce9112eae431c8e1
wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-de4898ebdc5ab81cedce89121ae9ac84
wired-in package base mapped to base-4.7.0.2-5ef1e7e809bc3b18d74efc783356e209
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.9.0.0-c1976a420ad8b9b589eee08844c59ba2
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags:
hiding package Cabal-1.18.1.5 to avoid conflict with later version Cabal-1.22.1.1
wired-in package ghc-prim mapped to ghc-prim-0.3.1.0-ec14d2f6075975a2ce9112eae431c8e1
wired-in package integer-gmp mapped to integer-gmp-0.5.1.0-de4898ebdc5ab81cedce89121ae9ac84
wired-in package base mapped to base-4.7.0.2-5ef1e7e809bc3b18d74efc783356e209
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.9.0.0-c1976a420ad8b9b589eee08844c59ba2
wired-in package dph-seq not found.
wired-in package dph-par not found.
*** Chasing dependencies:
Chasing modules from: *Main.hs
Main.hs:3:8:
Could not find module ‘Data.Natural’
Locations searched:
Data/Natural.hs
Data/Natural.lhs
*** Deleting temp files:
Deleting:
*** Deleting temp dirs:
Deleting:
【问题讨论】:
-
你更新你的 .cabal 文件了吗?
-
@Sigrlami 恐怕我不明白。我有一个名为
$HOME/.cabal和/tmp/haskell-example/.cabal-sandbox的目录,但没有.cabal文件。我需要做什么来更新它? -
当您在项目中使用命令
cabal init时,将创建描述所有需要的依赖项的foo.cabal文件,您需要手动添加它们。假设您的项目名称为foo。例如,github.com/sigrlami/pollock/blob/master/pollock.cabal
标签: haskell ghc cabal cabal-install