带有gcc错误的Haskell编译

带有gcc错误的Haskell编译,haskell,gcc,linker,Haskell,Gcc,Linker,我一直在尝试使用ghc编译Haskell代码(只是为了玩Haskell),但在gcc链接部分出现错误 ghc --make compileTest.hs Linking compileTest ... /usr/bin/ld: --hash-size=31: unknown option /usr/bin/ld: use the --help option for usage information collect2: error: ld returned 1 exit status 以下是

我一直在尝试使用ghc编译Haskell代码(只是为了玩Haskell),但在gcc链接部分出现错误

ghc --make compileTest.hs 
Linking compileTest ...
/usr/bin/ld: --hash-size=31: unknown option
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
以下是我的gcc版本:

gcc --version
gcc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
我不理解gcc接受的不同标志的微妙之处,在谷歌上找不到任何关于该错误的引用。另外,我认为我不能直接更改对gcc的调用,因为它是由ghc命令启动的,用于编译Haskell文件

详细版本如下所示

:~/haskell_code$ ghc --make compileTest.hs -v
Glasgow Haskell Compiler, Version 7.4.2, stage 2 booted by GHC version 7.4.2
Using binary package database: /usr/lib/ghc/package.conf.d/package.cache
wired-in package ghc-prim mapped to ghc-prim-0.2.0.0-7d3c2c69a5e8257a04b2c679c40e2fa7
wired-in package integer-gmp mapped to integer-gmp-0.4.0.0-af3a28fdc4138858e0c7c5ecc2a64f43
wired-in package base mapped to base-4.5.1.0-6e4c9bdc36eeb9121f27ccbbcb62e3f3
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.7.0.0-2bd128e15c2d50997ec26a1eaf8b23bf
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: -static
*** Chasing dependencies:
Chasing modules from: *compileTest.hs
Stable obj: [Main]
Stable BCO: []
Ready for upsweep
  [NONREC
      ModSummary {
         ms_hs_date = Sun Apr 21 23:11:03 IST 2013
         ms_mod = main:Main,
         ms_textual_imps = [import (implicit) Prelude]
         ms_srcimps = []
      }]
*** Deleting temp files:
Deleting: 
compile: input file compileTest.hs
Created temporary directory: /tmp/ghc20569_0
*** Checking old interface for main:Main:
[1 of 1] Skipping  Main             ( compileTest.hs, compileTest.o )
Upsweep completely successful.
*** Deleting temp files:
Deleting: /tmp/ghc20569_0/ghc20569_0.s
Warning: deleting non-existent /tmp/ghc20569_0/ghc20569_0.s
link: linkables are ...
LinkableM (Sun Apr 21 23:11:17 IST 2013) main:Main
   [DotO compileTest.o]
Linking compileTest ...
*** C Compiler:
'/usr/bin/gcc' '-fno-stack-protector' '-Wl,--hash-size=31' '-Wl,--reduce-memory-overheads' '-c' '/tmp/ghc20569_0/ghc20569_0.c' '-o' '/tmp/ghc20569_0/ghc20569_0.o' '-DTABLES_NEXT_TO_CODE' '-I/usr/lib/ghc/include'
*** C Compiler:
'/usr/bin/gcc' '-fno-stack-protector' '-Wl,--hash-size=31' '-Wl,--reduce-memory-overheads' '-c' '/tmp/ghc20569_0/ghc20569_0.s' '-o' '/tmp/ghc20569_0/ghc20569_1.o' '-DTABLES_NEXT_TO_CODE' '-I/usr/lib/ghc/include'
*** Linker:
'/usr/bin/gcc' '-fno-stack-protector' '-Wl,--hash-size=31' '-Wl,--reduce-memory-overheads' '-o' 'compileTest' 'compileTest.o' '-L/usr/lib/ghc/base-4.5.1.0' '-L/usr/lib/ghc/integer-gmp-0.4.0.0' '-L/usr/lib/ghc/ghc-prim-0.2.0.0' '-L/usr/lib/ghc' '/tmp/ghc20569_0/ghc20569_0.o' '/tmp/ghc20569_0/ghc20569_1.o' '-lHSbase-4.5.1.0' '-lHSinteger-gmp-0.4.0.0' '-lgmp' '-lHSghc-prim-0.2.0.0' '-lHSrts' '-lffi' '-lm' '-lrt' '-ldl' '-u' 'ghczmprim_GHCziTypes_Izh_static_info' '-u' 'ghczmprim_GHCziTypes_Czh_static_info' '-u' 'ghczmprim_GHCziTypes_Fzh_static_info' '-u' 'ghczmprim_GHCziTypes_Dzh_static_info' '-u' 'base_GHCziPtr_Ptr_static_info' '-u' 'base_GHCziWord_Wzh_static_info' '-u' 'base_GHCziInt_I8zh_static_info' '-u' 'base_GHCziInt_I16zh_static_info' '-u' 'base_GHCziInt_I32zh_static_info' '-u' 'base_GHCziInt_I64zh_static_info' '-u' 'base_GHCziWord_W8zh_static_info' '-u' 'base_GHCziWord_W16zh_static_info' '-u' 'base_GHCziWord_W32zh_static_info' '-u' 'base_GHCziWord_W64zh_static_info' '-u' 'base_GHCziStable_StablePtr_static_info' '-u' 'ghczmprim_GHCziTypes_Izh_con_info' '-u' 'ghczmprim_GHCziTypes_Czh_con_info' '-u' 'ghczmprim_GHCziTypes_Fzh_con_info' '-u' 'ghczmprim_GHCziTypes_Dzh_con_info' '-u' 'base_GHCziPtr_Ptr_con_info' '-u' 'base_GHCziPtr_FunPtr_con_info' '-u' 'base_GHCziStable_StablePtr_con_info' '-u' 'ghczmprim_GHCziTypes_False_closure' '-u' 'ghczmprim_GHCziTypes_True_closure' '-u' 'base_GHCziPack_unpackCString_closure' '-u' 'base_GHCziIOziException_stackOverflow_closure' '-u' 'base_GHCziIOziException_heapOverflow_closure' '-u' 'base_ControlziExceptionziBase_nonTermination_closure' '-u' 'base_GHCziIOziException_blockedIndefinitelyOnMVar_closure' '-u' 'base_GHCziIOziException_blockedIndefinitelyOnSTM_closure' '-u' 'base_ControlziExceptionziBase_nestedAtomically_closure' '-u' 'base_GHCziWeak_runFinalizzerBatch_closure' '-u' 'base_GHCziTopHandler_flushStdHandles_closure' '-u' 'base_GHCziTopHandler_runIO_closure' '-u' 'base_GHCziTopHandler_runNonIO_closure' '-u' 'base_GHCziConcziIO_ensureIOManagerIsRunning_closure' '-u' 'base_GHCziConcziSync_runSparks_closure' '-u' 'base_GHCziConcziSignal_runHandlers_closure'
/usr/bin/ld: --hash-size=31: unknown option
/usr/bin/ld: use the --help option for usage information
collect2: error: ld returned 1 exit status
*** Deleting temp files:
Deleting: /tmp/ghc20569_0/ghc20569_1.o /tmp/ghc20569_0/ghc20569_0.s /tmp/ghc20569_0/ghc20569_0.o /tmp/ghc20569_0/ghc20569_0.c
*** Deleting temp dirs:
Deleting: /tmp/ghc20569_0

问题是,正如Daniel Fisher所提到的,ghc似乎使用了旧版本ld特有的选项。通过将ld放在路径的第一位,可以覆盖ld的选择

您拥有的第一个测试
ld.bfd
(旧程序):

然后为本地程序创建一个目录。我使用~/bin。如果您还没有这样的目录,请将以下内容放入
.profile
文件中,然后重新启动所有shell(例如
bash

然后,为
ld.bfd
添加覆盖

$ cd bin
~/bin$ ln -s `which ld.bfd` ld
~/bin$ ls -l ld
lrwxrwxrwx 1 user user 15 Oct  1 15:44 ld -> /usr/bin/ld.bfd

这有帮助吗?

ghci compileTest.hs有效吗?您的
ld是什么?Mine(
GNULD(GNUBINUTILS;openSUSE 12.3)2.23.1
)理解
——hash size=31
。如果您的实际上是
gold
,我似乎记得GHC传递的标志有问题。“我不记得怎么治疗它了。”丹尼尔·费舍尔说,“我用的是金子。”。在切换到ld it链接后,没有任何投诉。谢谢
# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi
$ cd bin
~/bin$ ln -s `which ld.bfd` ld
~/bin$ ls -l ld
lrwxrwxrwx 1 user user 15 Oct  1 15:44 ld -> /usr/bin/ld.bfd