1

我一直在尝试使用 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
4

1 回答 1

0

问题在于 ghc 似乎使用了特定于旧版本 ld 的选项,正如 Daniel Fisher 所提到的。您可以通过将其放在您的路径中来覆盖 ld 的选择。

首先测试你有ld.bfd(旧程序):

$ which ld.bfd
/usr/bin/ld.bfd

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

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

然后,为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

这有帮助吗?

于 2013-10-01T14:45:46.447 回答