如何在GHC-8.2.2和Cabal-2.0.0.1中使用Text.Parsec

问题描述 投票:0回答:1

据我所知,Text.ParserCombinators.ParsecText.Parsec取代

在这里,这是我的环境

4.9.73-1-MANJARO

The Glorious Glasgow Haskell Compilation System, version 8.2.2

cabal-install version 2.0.0.1
compiled using version 2.0.1.0 of the Cabal library 

以下源代码是我的main.hs

module Main where
import System.Environment
import Text.Parsec

main :: IO ()
main = do
     args <- getArgs
     putStrLn (readExpr (args !! 0))

然后我编译它

$ ghc -package parsec -o main main.hs

它会出现以下错误消息

[1 of 1] Compiling Main             ( main.hs, main.o )

main.hs:3:1: error:
    Could not find module ‘Text.Parsec’
    There are files missing in the ‘parsec-3.1.11’ package,
    try running 'ghc-pkg check'.
    Use -v to see a list of the files searched for.
  |
3 | import Text.Parsec
  | ^^^^^^^^^^^^^^^^^^
rm: cannot remove '*.hi': No such file or directory
./run.sh: line 11: ./TestProj: No such file or directory

我确保我已经安装了parsec。所以我想问一下我做过的任何错误?

$ cabal install parsec
Resolving dependencies...
All the requested packages are already installed:
parsec-3.1.11
Use --reinstall if you want to reinstall anyway.
haskell ghc cabal parsec
1个回答
0
投票

Manjaro可能继承了Arch与Haskell的问题。

What is going on

Arch安装动态库,但默认情况下ghc静态链接。这也是错误消息“...包中缺少文件”,表明包存在但不包含ghc正在寻找的内容。

如果我尝试使用-v verbose标志进行编译,则错误消息将扩展为:

ghc -v main.hs

(...)
Locations searched:
  Text/Parsec.hs
  Text/Parsec.lhs
  Text/Parsec.hsig
  Text/Parsec.lhsig
  /usr/lib/ghc-8.2.2/site-local/parsec-3.1.11/Text/Parsec.hi
(...)

特别是,查看上次报告的位置,您的系统可能会有所不同;如果我的猜测是正确的,ghc正在寻找一个静态接口文件.hi,因为消息指示,但只有一个动态的.dyn_hi

Fix

-dynamic标志编译。

 ghc -dynamic main.hs

如果有效,请阅读此内容以修复设置:

https://wiki.archlinux.org/index.php/Haskell

您必须在静态和动态链接之间进行选择;我实际上并不理解这里的权衡。

© www.soinside.com 2019 - 2024. All rights reserved.