我正在经历现实世界的 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。
我在 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
但我不记得了...
(我最初在互联网上的某个地方找到了这个,但我不记得在哪里。它也花了我一段时间。)
您最近更新到 Snow Leopard 了吗?我相信当您尝试在 Snow Leopard 中使用使用 Leopard 构建的可执行文件时,就会发生这种情况。