ghc can't find my cabal installed packages

冷暖自知 提交于 2021-02-18 21:12:57

问题


I've installed ghc 6.12.3, and then the Haskell Platform. I'm trying to compile a test program:

$ ghc test.hs
test.hs:3:0:
    Failed to load interface for `Bindings':
      Use -v to see a list of the files searched for.

so, naturally, I do

cabal install Bindings

Which works fine, and places the package in ~/.cabal/lib/bindings-0.1.2 The problem is, that when I go to compile again with ghc, it still doesn't find the package I've installed with cabal. compiling in verbose mode gives:

ghc -v test.hs
Using binary package database: /home/ludflu/ghc/lib/ghc-6.12.3/package.conf.d/package.cache
Using binary package database: /home/ludflu/.ghc/x86_64-linux 6.12.3/package.conf.d/package.cache

As suggested by another stackoverflow user, I tried:

ghc-pkg describe rts > rts.pkg
vi rts.pkg                      # add the /home/ludflu/.cabal/lib to `library-dirs` field
ghc-pkg update rts.pkg

But to no avail. How to I add the .cabal to the list of package directories to search? Thank you!


回答1:


You can check which packages are installed with ghc-pkg list. It may be that you need to either specify the packages to ghc with -package <pkgname> or I believe adding --make to will trigger a chasing down of dependencies, including packages.

Edit: the bindings package is obsolete indeed, see the hackage page. This isn't a package management problem, the only module available is Bindings.Deprecated, which you are perfectly able to load, even though it is an empty module. I believe the relevant parts have been broken out into bindings-<module>, so if you want the bindings functionality you should look to those packages.




回答2:


http://www.haskell.org/haskellwiki/Cabal-install

One thing to be especially aware of, is that the packages are installed locally by default by cabal, whereas the commands

runhaskell Setup configure
runhaskell Setup build
runhaskell Setup install

install globally by default. If you install a package globally, the local packages are ignored. The default for cabal-install can be modified by editing the configuration file.

I was getting the same error with the runhaskell command. I used the cabal in the directory that had the .cabal file and was able to resolve the error.



来源:https://stackoverflow.com/questions/4641684/ghc-cant-find-my-cabal-installed-packages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!