Haskell Parsec コンパイル エラー
質問
事前に構築されたインストーラー 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をインストールしました。
何が問題なのか何かわかる人はいますか?
解決
ghc --make -o read read.hs
を試してみてください。 GHCは、リンカー依存の世話をします。
他のヒント
私はこの作品を作るための一つの他の方法を出します。
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 /ドキュメント/最新/ HTML / users_guide /のpackages.htmlする
によると Parsec ドキュメント (セクション 1.2.1 GHC によるコンパイル)、次のようにする必要があります。
ファイルを一緒にリンクするときは、GHCにライブラリ(-l)を見つけることができる場所を伝え、Parsecライブラリ(-l)にもリンクする必要があります。
ghc -o myprogram myfile1.o myfile2.o -Lc:\parsec -lparsec
このドキュメント Haskell コンパイラが役立つかもしれません。
所属していません StackOverflow