Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell Parsec compile error

I've installed Haskell via the pre built installer v6.8.2.

When trying to compile this sample file with GHC

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

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

I get the following error:

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

I have installed Parsec via cabal.

Does anyone have any idea's as to what is wrong?

like image 686
chollida Avatar asked Nov 04 '09 17:11

chollida


3 Answers

Try ghc --make -o read read.hs. GHC will take care of linker dependencies.

like image 177
Cat Plus Plus Avatar answered Nov 10 '22 21:11

Cat Plus Plus


I'll put out one other way to make this work

ghc -package parsec -o read read.hs

From the ghc documentation

-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.

see http://www.haskell.org/ghc/docs/latest/html/users_guide/packages.html

like image 28
chollida Avatar answered Nov 10 '22 22:11

chollida


According to the Parsec docs (section 1.2.1 Compiling with GHC), you should do this:

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 on the Haskell compiler may help.

like image 44
Jeff Yates Avatar answered Nov 10 '22 22:11

Jeff Yates