我已经通过预构建的安装程序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。
有没有人知道什么是错的?
答案 0 :(得分:9)
试试ghc --make -o read read.hs
。 GHC将负责链接器依赖。
答案 1 :(得分: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
答案 2 :(得分:1)
根据the Parsec docs(第1.2.1节与GHC一起编译),你应该这样做:
Haskell编译器上的将文件链接在一起时, 你需要告诉GHC它能找到的地方 库(-L)并与之链接 Parsec库也是(-l):
的ghc -o myprogram myfile1.o myfile2.o -Lc:\parsec -lparsec
强>
This documentation可能有所帮助。