OS X Lion 上的系统出现 GHC 错误
我尝试使用 ghc 编译和链接简单的程序,但在链接过程中失败:
import System (getArgs)
main = do
args <- getArgs
print args
我尝试使用编译
% 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
但是,使用 --make 编译时:
% ghc --make Main.hs
一切正常(除了大量的 ld 警告)
有关环境的更多信息:
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.3
来自 Haskell Platform for Mac OS X 10.6(英特尔,32 位 GHC)
系统:Max OS X Lion 10.7.2
有什么问题吗?
(顺便说一句,我尝试安装 HP x64 但在安装过程中失败)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
迈克尔在历史上是正确的。使用
--make
,ghc 会找出它必须使用哪些包并自行链接(除非两个已安装的包公开相同的模块名称,然后它无法确定要使用哪个包),如果没有--make
,你必须告诉它。但是,从 7.0 开始,--make
是 ghc 的默认模式,因此普通的ghc Main.hs
现在与ghc --make Main 相同。 HS。这里的区别是两步编译。我不知道确切的细节,但原因是模块
在默认包中找不到该符号。您必须明确告诉它在 haskell98 包中查找,System
位于 haskell98 包中(建议,请使用分层模块, getArgs 应通过 System.Environment 导入,截至7.2 后,haskell98 不能与 base 一起使用,默认情况下没有链接进来。因此 ghc -o Main Main.oghc -c -O Main.hs; ghc -package haskell98 -o Main Main.o
应该可以工作(它在这里可以工作,我已经用 7.0.4 进行了测试以确保)。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 plainghc Main.hs
is now the same asghc --make Main.hs
. The difference here is the two-step compilation. I don't know the precise details, but the cause is that the moduleSystem
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. Soghc -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).也许是因为你正在使用系统中的某些东西? ghc --make 可能会自动检测需要链接的 Haskell 库,而 ghc 本身则不会。
Perhaps it's because you're using something from System?
ghc --make
probably auto-detects which Haskell libraries it needs to link, andghc
by itself does not.