Reputation: 331
I tried to compile and link simple program using ghc, but it failed during linking:
import System (getArgs)
main = do
args <- getArgs
print args
I tried to compile with
% ghc -c -O Main.hs
% ghc -o Main Main.o
ld: warning: could not create compact unwind for .LFB3: non-standard register 5 being saved in prolog
Undefined symbols for architecture i386:
"___stginit_haskell98zm1zi1zi0zi1_System_", referenced from:
___stginit_Main_ in Main.o
ld: symbol(s) not found for architecture i386
collect2: ld returned 1 exit status
zsh: exit 1 ghc -o Main Main.o
However, when compiling with --make:
% ghc --make Main.hs
everything works (besides tons of ld warnings)
Some more informations about environment:
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.3
From Haskell Platform for Mac OS X 10.6 (Intel, 32 bit GHC)
System: Max OS X Lion 10.7.2
Any ideas what's wrong?
(Btw, I tried to install HP x64 but it failed during installation)
Upvotes: 3
Views: 557
Reputation: 183878
Michael is historically right. With --make
, ghc figures out which packages it has to use and link in by itself (unless two installed packages expose the same module name, then it can't figure out which one to use), without --make
, you have to tell it. However, as of 7.0, --make
is the default mode of ghc, so plain ghc Main.hs
is now the same as ghc --make Main.hs
. The difference here is the two-step compilation. I don't know the precise details, but the cause is that the module System
is in the haskell98 package (a propos, please use the hierarchical modules, getArgs should be imported via System.Environment, as of 7.2, haskell98 can't be used together with base), which by default is not linked in. So ghc -o Main Main.o
doesn't find the symbol in the default packages. You'd have to tell it explicitly to look in the haskell98 package, ghc -c -O Main.hs; ghc -package haskell98 -o Main Main.o
should work (and it works here, I've tested with 7.0.4 to make sure).
Upvotes: 5
Reputation: 701
Perhaps it's because you're using something from System? ghc --make
probably auto-detects which Haskell libraries it needs to link, and ghc
by itself does not.
Upvotes: 3