简体   繁体   English

GHC找不到已安装的模块

[英]GHC can not find installed module

My haskell installation can not find bytestring module installed by operating system 我的haskell安装找不到操作系统安装的字节串模块

$ ghci
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 +Data.ByteString.Lazy

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

But I have installed this module using yum: 但是我已经使用yum安装了这个模块:

$ rpm -ql ghc-bytestring
/usr/lib64/ghc-7.6.3/bytestring-0.10.0.2
/usr/lib64/ghc-7.6.3/bytestring-0.10.0.2/libHSbytestring-0.10.0.2-ghc7.6.3.so
/usr/share/doc/ghc-bytestring
/usr/share/doc/ghc-bytestring/LICENSE

What is wrong? 怎么了?

If this is happening, you should be able to figure out more via ghc-pkg list . 如果发生这种情况,您应该可以通过ghc-pkg list找出更多信息。 This could happen, for example, if the binary package provided by your software repository was broken; 例如,如果您的软件存储库提供的二进制软件包被破坏,则可能会发生这种情况。 ghc-pkg list would report that. ghc-pkg list将报告该情况。 In general, either GHC is not looking for packages in /usr/lib64/ghc-7.6.3/ or else that directory has a package.cache which was not updated to reflect the new package. 通常,GHC不在/usr/lib64/ghc-7.6.3/寻找软件包,或者该目录中的package.cache没有被更新以反映新软件包。

One thing that could cause GHC to look in the wrong place is if there are multiple GHCs on the machine: for example if which ghc reveals /usr/local/bin/ghc then you probably compiled GHC from source at some point and its packages are occupying some /usr/local/lib/ghc-7.6.3/package.conf.d/ folder, while your repository has installed /usr/bin/ghc which is looking in the folder you want. 可能导致GHC放在错误位置的一件事是,如果机器上有多个GHC:例如,如果which ghc显示/usr/local/bin/ghc则您可能在某个时候从源代码编译了GHC,并且其软件包是占用一些/usr/local/lib/ghc-7.6.3/package.conf.d/文件夹,而您的存储库已安装/usr/bin/ghc ,该文件夹正在所需的文件夹中查找。

Anyway, fixes: if the package.cache file exists and has a valid entry for the file, then you can run ghc -package-conf /path/to/package.cache ... to add those packages to your executable. 无论如何,修复:如果package.cache文件存在并且具有该文件的有效条目,那么您可以运行ghc -package-conf /path/to/package.cache ...将那些软件包添加到可执行文件中。 If you have further problems, ghc -v ... is a great resource for debugging "which version of that package is being used here?" 如果您还有其他问题, ghc -v ...是调试“此处使用哪个版本的软件包?”的好资源。 types of problems. 问题类型。

If the package.cache file does not exist then you've got a bigger problem, and probably the easiest way to move forward is to look for a directory under /home which appears on ghc-pkg list . 如果package.cache文件不存在,那么您会遇到更大的问题,而前进的最简单方法可能是在ghc-pkg list上的/home下查找目录。 Install the required package to that directory and GHC should pick up on it even though it doesn't understand these bigger contexts. 将所需的软件包安装到该目录,即使GHC无法理解这些较大的上下文,GHC也应继续安装。 You could also start working with a cabal sandbox of local packages to your project. 你也可以开始工作cabal本地包的沙箱到您的项目。

Situation here is similiar to C++ you have libraries used during dynamic linking stage and header used for compilation. 这里的情况与C ++类似,您具有在动态链接阶段使用的库和用于编译的标头。 In Fedora packages like ghc-bytestring are only libraries without headers. 在Fedora包中,如ghc-bytestring只是没有标题的库。 To install headers I had to install ghc-bytestring-devel package. 要安装标题,我必须安装ghc-bytestring-devel软件包。

An example on Fedora 24: 关于Fedora 24的示例:

server.hs:7:8:
    Could not find module ‘Data.Text’
    Perhaps you meant Data.Set (from containers-0.5.5.1)
    Locations searched:
      Data/Text.hs
      Data/Text.lhs

So change to user root , then: 因此,更改为root用户,然后:

What packages are there? 有什么包装?

# dnf search ghc|grep text

ghc-text.x86_64 : An efficient packed Unicode text type
ghc-boxes.x86_64 : 2D text pretty-printing library
ghc-pango.x86_64 : Binding to the Pango text rendering engine
ghc-css-text.x86_64 : CSS parser and renderer
ghc-hgettext.x86_64 : Haskell binding to libintl
ghc-attoparsec.x86_64 : Fast combinator parsing for bytestrings and text
ghc-text-devel.x86_64 : Haskell text library development files
ghc-blaze-textual.x86_64 : Fast rendering of common datatypes
ghc-css-text-devel.x86_64 : Haskell css-text library development files
ghc-hgettext-devel.x86_64 : Haskell hgettext library development files
ghc-blaze-textual-devel.x86_64 : Haskell blaze-textual library development files

So what's installed? 那么安装了什么?

# rpm --query ghc-text
ghc-text-1.1.1.3-3.fc24.x86_64

# rpm --query ghc-text-devel
package ghc-text-devel is not installed

So let's install the devel package. 因此,让我们安装devel软件包。

# dnf install ghc-text-devel
Installed:
  ghc-text-devel.x86_64 1.1.1.3-3.fc24

...and compilation succeeds after that. ...然后编译成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM