【问题标题】:GHC error with System on OS X LionOS X Lion 上的系统出现 GHC 错误
【发布时间】:2011-11-13 01:53:22
【问题描述】:

我尝试使用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

来自适用于 Mac OS X 10.6(英特尔,32 位 GHC)的 Haskell 平台

系统:Max OS X Lion 10.7.2

有什么想法吗?

(顺便说一句,我尝试安装 HP x64,但在安装过程中失败)

【问题讨论】:

    标签: macos haskell ghc


    【解决方案1】:

    迈克尔在历史上是正确的。使用--make,ghc 会确定它必须使用哪些包并自行链接(除非两个已安装的包暴露了相同的模块名称,否则它无法确定使用哪一个),没有--make,你有告诉它。但是,从 7.0 开始,--make 是 ghc 的默认模式,因此普通的 ghc Main.hs 现在与 ghc --make Main.hs 相同。这里的区别在于两步编译。具体细节我不清楚,但原因是模块System在haskell98包中(建议,请使用分层模块,getArgs应该通过System.Environment导入,从7.2开始,haskell98可以' t 与 base 一起使用),默认情况下未链接。因此 ghc -o Main Main.o 在默认包中找不到符号。你必须明确告诉它查看 haskell98 包,ghc -c -O Main.hs; ghc -package haskell98 -o Main Main.o 应该可以工作(它在这里工作,我已经用 7.0.4 测试过以确保)。

    【讨论】:

      【解决方案2】:

      也许是因为您使用了 System 中的某些东西? ghc --make 可能会自动检测它需要链接哪些 Haskell 库,而 ghc 本身不会。

      【讨论】:

        猜你喜欢
        • 2011-10-19
        • 1970-01-01
        • 1970-01-01
        • 2011-10-15
        • 2012-06-27
        • 1970-01-01
        • 2013-01-02
        • 2012-11-21
        • 1970-01-01
        相关资源
        最近更新 更多