Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell program with Data.Set doesnt compile

Tags:

gcc

haskell

ghc

I write the following file temp.hs:

import qualified Data.Set
import System.Environment

main :: IO ()
main = do
        args <- getArgs
        let fname = head args
        print (fname)

It loads in ghci without errors:

$ ghci
GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :load temp.hs 
[1 of 1] Compiling Main             ( temp.hs, interpreted )
Ok, modules loaded: Main.
*Main> 

When I try to compile it, I get the following errors:

$ ghc temp.hs -o temp
Undefined symbols:
  "___stginit_containerszm0zi3zi0zi0_DataziSet_", referenced from:
      ___stginit_Main_ in temp.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

If I take the import Data.Set out, it compiles fine.

Version Info:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.12.3

$ gcc --ver
Using built-in specs.
Target: i686-apple-darwin10
Configured with: /var/tmp/gcc_40/gcc_40-5494~112/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin10 --with-arch=apple --with-tune=generic --host=i686-apple-darwin10 --target=i686-apple-darwin10
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5494)
like image 965
highBandWidth Avatar asked Aug 12 '26 08:08

highBandWidth


2 Answers

You can add packages individually (as KennyTM suggests), or you can just use --make, which is much more convenient in a number of ways:

ghc --make temp.hs -o temp

This will cause GHC to look for any required modules among its installed packages in exactly the same way that GHCi does.

like image 177
Travis Brown Avatar answered Aug 14 '26 23:08

Travis Brown


ghc -package containers temp.hs -o temp

You can check which package may be needed with ghci, when you actually use the library:

  GHCi, version 6.12.3: http://www.haskell.org/ghc/  :? for help
  Loading package ghc-prim ... linking ... done.
  Loading package integer-gmp ... linking ... done.
  Loading package base ... linking ... done.
  Loading package ffi-1.0 ... linking ... done.
  Ok, modules loaded: Main.
  Prelude Main> Data.Set.singleton 0
> Loading package array-0.3.0.1 ... linking ... done.
> Loading package containers-0.3.0.0 ... linking ... done.
  fromList [0]
  Prelude Main> 
like image 26
kennytm Avatar answered Aug 14 '26 23:08

kennytm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!