GHC package is hidden

烂漫一生 提交于 2019-12-07 00:28:49

问题


I'm trying to run this simple example that I got from the Haskell wiki.

import GHC
import GHC.Paths ( libdir )
import DynFlags

main = 
    defaultErrorHandler defaultFatalMessager defaultFlushOut $ do
      runGhc (Just libdir) $ do
        dflags <- getSessionDynFlags
        setSessionDynFlags dflags
        target <- guessTarget "test_main.hs" Nothing
        setTargets [target]
        load LoadAllTargets

The error messages I'm getting are:

amy@wombat$ ghc --make amy15.hs 

amy15.hs:1:8:
    Could not find module ‘GHC’
    It is a member of the hidden package ‘ghc-7.8.3’.
    Use -v to see a list of the files searched for.

amy15.hs:3:8:
    Could not find module ‘DynFlags’
    It is a member of the hidden package ‘ghc-7.8.3’.
    Use -v to see a list of the files searched for.

Now, ghc-7.8.3 is what I'm using to do the compilation, so obviously the package is installed.

amy@wombat$ cabal info ghc
* ghc              (library)
    Versions available: [ Not available from server ]
    Versions installed: 7.8.3
... and so on

Why can't GHC see the ghc package?


回答1:


Most packages are indeed hidden.

To unhide them temporarily, you may use ghc --make amy15.hs -package ghc-7.8.3.

To unhide permanently, use the method @mhwombat suggested.




回答2:


Apparently the ghc package is hidden by default, at least if you install ghc manually the way I did, rather than installing the Haskell platform. So I needed to "un-hide" the package as follows:

sudo ghc-pkg expose ghc


来源:https://stackoverflow.com/questions/26145383/ghc-package-is-hidden

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