17

I wrote a basic hello world program in haskel and tried to compile it with: ghc filename.hs. It produces .hi and .o files but no executable and displays this error in the linker:

marox@IT-marox:~/Marox$ ghc tupel.hs
Linking tupel ...
/usr/bin/ld: --hash-size=31: unknown option
/usr/bin/ld: use the --help option for usage information
collect2: ld returned 1 exit status

Googling didn't return any useful information.

I am on ubuntu 12.04.

How can I fix this?

sloth
  • 99,095
  • 21
  • 171
  • 219
Selina Paulson
  • 173
  • 1
  • 5

2 Answers2

19

Have you binutils-gold installed? If yes, this is the problem (since the gold linker does not support --hash-size AFAIK).

Possible solutions:

  1. remove gold
  2. your ld probably links to ld.gold, so change the symlink to ld.ld
  3. tell the haskell compiler explicitly which linker to use with the -pgml option: ghc -pgml ld.ld tupel.hs
  4. install ghc from source, since the configure script of ghc will then build ghc so that it won't use --hash-size
  5. Depending on your version of ghc, you can adjust the linker settings in ghc's setting file /usr/lib/ghc-your.ghc.version/settings
sloth
  • 99,095
  • 21
  • 171
  • 219
  • Removed gold. Did step 2 and got this: "ghc: could not execute: ld.ld" – Selina Paulson Oct 24 '12 at 09:56
  • 1
    i didn't mean to apply *all* of these above, just one of them :-) If you have remove gold, everything *should* be fine. Just ensure `/usr/bin/ld` is actually there, and if it's a symlink, it has to point to the GNU ld. When you install gold, it will move `ld` to `ld.ld`, install `ld.gold`, and then link `ld` to `ld.gold` (AFAIK). Hope it is clearer now. – sloth Oct 24 '12 at 10:03
  • `ghc -pgml ld` will not work. According to dcoutts, the argument to `-pgml` has to be `gcc` or something similar. The linker has to be changed by passing an argument to the pgml with `-optl`. – nh2 Apr 19 '13 at 12:55
  • If you want to use gold and work around `--hash-size=31: unknown option`, please see http://stackoverflow.com/a/16105691/263061. – nh2 Apr 19 '13 at 13:27
  • [GHC has now official support to use `gold` for linking](http://stackoverflow.com/questions/43243322/how-to-link-with-the-gnu-gold-linker-instead-of-ld-in-haskell/) and will not pass the problematic `--hash-size` flag when told to use gold. – nh2 Apr 05 '17 at 23:40
2

Update - gold on Ubuntu 12.10 appears to move GNU ld to ld.bfd. To fix this problem I deleted the ld link as recommended and remade the link with

  ln -s ld.bfd ld

ghc compilations are now going through.

(Couldn't see how to subvert the settings file in usr/lib/ghc, as the entry is for gcc which passes through its commandline to ld, although this would have been my preferred option, in case something else needs ld to be the way it was.)

Thanks to Dominic for the pointer of where to look! It was driving me crazy...

masoud
  • 55,379
  • 16
  • 141
  • 208