6

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

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

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

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

我收到以下错误:

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。

有没有人知道什么是错的?

4

3 回答 3

9

试试ghc --make -o read read.hs。GHC 将处理链接器依赖关系。

于 2009-11-04T18:07:26.540 回答
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

于 2009-11-04T19:41:09.727 回答
1

根据Parsec 文档(第 1.2.1 节使用 GHC 编译),您应该这样做:

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

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

于 2009-11-04T18:02:45.037 回答