2009-11-04 35 views
6

Tôi đã cài đặt Haskell qua trình cài đặt được tạo sẵn v6.8.2.Lỗi biên dịch Haskell Parsec

Khi cố gắng để biên dịch tập tin mẫu này với GHC

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

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

tôi nhận được lỗi sau:

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 

Tôi đã cài đặt Parsec qua cabal.

Có ai có ý tưởng gì về điều gì sai không?

Trả lời

9

Hãy thử ghc --make -o read read.hs. GHC sẽ chăm sóc các phụ thuộc liên kết.

+0

Điều này dường như không hoạt động, cảm ơn rất nhiều – chollida

1

Theo the Parsec docs (phần 1.2.1 Biên soạn với GHC), bạn nên làm điều này:

When your linking the files together, you need to tell GHC where it can find libraries (-L) and to link with the Parsec library too (-l):
ghc -o myprogram myfile1.o myfile2.o -Lc:\parsec -lparsec

This documentation trên trình biên dịch Haskell có thể giúp đỡ.

+0

Không khá gì tôi đang tìm kiếm nhưng cảm ơn bạn anyway để thử;) – chollida

+0

Bạn được chào đón. Đó là một dự đoán. –

2

tôi sẽ đưa ra một cách khác để làm cho công việc này

ghc -package parsec -o read read.hs 

Từ các tài liệu 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. 

thấy http://www.haskell.org/ghc/docs/latest/html/users_guide/packages.html