OS X Lion 上的系统出现 GHC 错误

发布于 2024-12-14 21:49:15 字数 947 浏览 4 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

优雅的叶子 2024-12-21 21:49:15

迈克尔在历史上是正确的。使用 --make,ghc 会找出它必须使用哪些包并自行链接(除非两个已安装的包公开相同的模块名称,然后它无法确定要使用哪个包),如果没有 --make,你必须告诉它。但是,从 7.0 开始,--make 是 ghc 的默认模式,因此普通的 ghc Main.hs 现在与 ghc --make Main 相同。 HS。这里的区别是两步编译。我不知道确切的细节,但原因是模块 System 位于 haskell98 包中(建议,请使用分层模块, getArgs 应通过 System.Environment 导入,截至7.2 后,haskell98 不能与 base 一起使用,默认情况下没有链接进来。因此 ghc -o Main Main.o 在默认包中找不到该符号。您必须明确告诉它在 haskell98 包中查找,ghc -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 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).

樱娆 2024-12-21 21:49:15

也许是因为你正在使用系统中的某些东西? 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, and ghc by itself does not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文