已安装Haskell软件包但未找到

时间:2015-02-20 14:57:22

标签: haskell cabal cabal-install

我安装了图表,它似乎就在那里,但GHCi找不到它。我尝试将本地沙箱添加到命令行(-package-db),但仍然没有运气。 有什么建议吗?

   C:\Users\guthrie>
   C:\Users\guthrie>cabal install diagrams
    Resolving dependencies...
    All the requested packages are already installed:
   diagrams-1.2
   Use --reinstall if you want to reinstall anyway.

我发现它:

  C:\Users\guthrie\.cabal-sandbox\i386-windows-ghc-7.6.3-packages.conf.d
        (diagrams-1.2, diagrams-contrib, -core, -lib, -svg) 

但是运行:“cabal repl”或使用GHC(i)标志“ -package-db = ... ” 找不到它:

C:\Users\guthrie>cabal repl
GHCi, version 7.6.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :m + Diagrams.Prelude

<no location info>:
    Could not find module `Diagrams.Prelude'
   It is not a module in the current program, or in any known package.
Prelude>

澄清;忽略cabal调用,直接使用GHC / i,以及程序diagramDemo.hs:

--  http://projects.haskell.org/diagrams/doc/quickstart.html
--
import Diagrams.Prelude
import Diagrams.Backend.SVG.CmdLine

main = mainWith (circle 1 :: Diagram B R2)

给出:

C:\Users\guthrie\Desktop\xFer\Graphics>ghc --make diagramsDemo.hs

diagramsDemo.hs:7:8:
    Could not find module `Diagrams.Backend.SVG.CmdLine'
    Use -v to see a list of the files searched for.

C:\Users\guthrie\Desktop\xFer\Graphics>ghc --make diagramsDemo.hs -package-db=C:\Users\guthrie\.cabal-sandbox\i386-windows-ghc-7.6.3-packages.conf.d

diagramsDemo.hs:7:8:
    Could not find module `Diagrams.Backend.SVG.CmdLine'
    Use -v to see a list of the files searched for.

1 个答案:

答案 0 :(得分:5)

正如bheklilr所说,如果ghcicabal repl启动,它只会在.cabal文件中找到指定为依赖项的包。

但是您可以使用cabal exec ghci启动它,然后它会找到沙箱中安装的所有软件包。

调用ghccabal buildcabal exec ghc)的情况也是如此,但请注意,如果要传递标记,则必须使用--,例如cabal exec ghc -- -O2 Main.hs。或者,您可以使用cabal exec bash并在新shell中启动ghcighc

Cabal 1.20添加了

cabal exec