我在(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:
sinelaw.. 7
如果您正在进行手动黑客攻击,则可以将沙箱的pkg db位置传递给ghc,例如:
ghc Main.hs -package-db .cabal-sandbox/x86_64-linux-ghc-7.10.2-packages.conf.d/
但是,使用沙箱的"常规"方法是始终使用cabal build
(或cabal install
不使用参数)进行编译,而不是直接运行ghc.
跑cabal init
,回答你的问题
编辑生成的foo.cabal
文件(foo
是包的名称).
运行cabal build
或cabal install
- 这将为您运行ghc.
编辑cabal文件时,检查导出的模块(如果是lib)是否已列出,并且主src是否正确.还要确保子句natural-numbers
中列出的依赖项build-depends:
.
如果您正在进行手动黑客攻击,则可以将沙箱的pkg db位置传递给ghc,例如:
ghc Main.hs -package-db .cabal-sandbox/x86_64-linux-ghc-7.10.2-packages.conf.d/
但是,使用沙箱的"常规"方法是始终使用cabal build
(或cabal install
不使用参数)进行编译,而不是直接运行ghc.
跑cabal init
,回答你的问题
编辑生成的foo.cabal
文件(foo
是包的名称).
运行cabal build
或cabal install
- 这将为您运行ghc.
编辑cabal文件时,检查导出的模块(如果是lib)是否已列出,并且主src是否正确.还要确保子句natural-numbers
中列出的依赖项build-depends:
.