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

カバール経由でParsecをインストールしました。

何が悪いのかについて誰かが何か考えを持っていますか?

4

3 に答える 3

9

試してみてくださいghc --make -o read read.hs。GHCはリンカーの依存関係を処理します。

于 2009-11-04T18:07:26.540 に答える
2

これを機能させるためのもう1つの方法を紹介します

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 Compiling with GHC) によると、次のようにする必要があります。

ファイルを一緒にリンクするとき、GHC にライブラリを見つけることができる場所を伝え (-L)、Parsec ライブラリともリンクする (-l) 必要があります。
ghc -o myprogram myfile1.o myfile2.o -Lc:\parsec -lparsec

Haskell コンパイラに関するこのドキュメントが役立つ場合があります。

于 2009-11-04T18:02:45.037 に答える