Haskell Parsec编译错误

6

我已经通过预先构建的安装程序v6.8.2安装了Haskell。

尝试使用GHC编译此示例文件时

module Main where
import Text.ParserCombinators.Parsec
import System.Environment

main :: IO ()
main = do args <- getArgs
          putStrLn ("Hello")

I get the following error:

D:\src\Haskell>ghc -o read read.hs
ghc -o read read.hs
read.o(.text+0x1b5):fake: undefined reference to   `__stginit_parseczm2zi1zi0zi0_TextziParserCombinatorsziParsec_'
collect2: ld returned 1 exit status

我已经通过cabal安装了Parsec。

有人知道出了什么问题吗?

3个回答

9
尝试运行命令ghc --make -o read read.hs。GHC会处理链接器依赖关系。

2
我还有另一种方法让这个工作。
ghc -package parsec -o read read.hs

从 GHC 文档中
-package P

This option causes the installed package P to be exposed. The package P can be 
specified in full with its version number (e.g. network-1.0) or the version number 
can be omitted if there is only one version of the package installed. If there are 
multiple versions of P installed, then all other versions will become hidden.

The -package P option also causes package P to be linked into the resulting 
executable or shared object. Whether a packages' library is linked statically or 
dynamically is controlled by the flag pair -static/-dynamic.

请参阅 http://www.haskell.org/ghc/docs/latest/html/users_guide/packages.html


1

根据Parsec文档(1.2.1节GHC编译),您应该执行以下操作:

当您将文件链接在一起时, 您需要告诉GHC可以在哪里找到库(-L)并链接 Parsec库(-l):
ghc -o myprogram myfile1.o myfile2.o -Lc:\parsec -lparsec

Haskell编译器的这份文档可能会有所帮助。


不完全是我在寻找的东西,但无论如何还是谢谢你的尝试;) - chollida

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接