0

我正在经历Real world Haskell,并得到了这个例子:

-- file: ch04/InteractWith.hs
-- Save this in a source file, e.g. Interact.hs

import System.Environment (getArgs)

interactWith function inputFile outputFile = do
  input <- readFile inputFile
  writeFile outputFile (function input)

main = mainWith myFunction
  where mainWith function = do
          args <- getArgs
          case args of
            [input,output] -> interactWith function input output
            _ -> putStrLn "error: exactly two arguments needed"

        -- replace "id" with the name of our function below
        myFunction = id

但是当我尝试编译它(ghc --make InteractWith)时,我得到了这个错误:

$ ghc --make InteractWith
[1 of 1] Compiling Main             ( InteractWith.hs, InteractWith.o )

/var/folders/38/38dlZO7fEXyCgGIFUZA0Ok+++TI/-Tmp-/ghc91310_0/ghc91310_0.s:309:0:
    suffix or operands invalid for `push'

/var/folders/38/38dlZO7fEXyCgGIFUZA0Ok+++TI/-Tmp-/ghc91310_0/ghc91310_0.s:358:0:
    suffix or operands invalid for `push'

/var/folders/38/38dlZO7fEXyCgGIFUZA0Ok+++TI/-Tmp-/ghc91310_0/ghc91310_0.s:384:0:
    32-bit absolute addressing is not supported for x86-64

/var/folders/38/38dlZO7fEXyCgGIFUZA0Ok+++TI/-Tmp-/ghc91310_0/ghc91310_0.s:384:0:
    cannot do signed 4 byte relocation

/var/folders/38/38dlZO7fEXyCgGIFUZA0Ok+++TI/-Tmp-/ghc91310_0/ghc91310_0.s:387:0:
    32-bit absolute addressing is not supported for x86-64

/var/folders/38/38dlZO7fEXyCgGIFUZA0Ok+++TI/-Tmp-/ghc91310_0/ghc91310_0.s:387:0:
    cannot do signed 4 byte relocation

我在 Mac OS 10.6 (Snow Leopard) 上使用 GHC 6.10.4。

4

2 回答 2

3

我在 Snow Leopard 中编译几乎任何东西时都遇到了类似的问题。我找到的解决方案是将/usr/bin/ghc(实际上只是一个shell脚本)的内容替换为以下内容:

#!/bin/sh

exec /Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.4/ghc -B/Library/Frameworks/GHC.framework/Versions/610/usr/lib/ghc-6.10.4/. -optc-m32 -opta-m32 -optl-m32 -dynload wrapped ${1+"$@"}

我想它实际上只是添加-optc-m32 -opta-m32 -optl-m32,但我不记得了......

(我最初在互联网上的某个地方找到了这个,但我不记得在哪里。我也花了一段时间。)

于 2009-11-30T21:44:58.050 回答
0

你最近更新到雪豹了吗?我相信当您尝试在 Snow Leopard 中使用使用 Leopard 构建的可执行文件时会发生这种情况。

于 2009-11-30T23:12:09.527 回答