Stack Error: Couldn't figure out linker information

Stack used to work for me when I used the stack package from the package repo.

I switched over to ghcup to better manage versions, and now stack is complaining about not finding a linker. However, I have GNU ld on my system, what can I do here?

I have tested with Stack 2.9.1 and 2.9.3, and ghc 9.4.4.

$ stack build
[1 of 2] Compiling Main             ( /home/daniel/.stack/setup-exe-src/setup-SvXsv1f_.hs, /home/daniel/.stack/setup-exe-src/setup-SvXsv1f_.o )
[2 of 2] Compiling StackSetupShim   ( /home/daniel/.stack/setup-exe-src/setup-shim-SvXsv1f_.hs, /home/daniel/.stack/setup-exe-src/setup-shim-SvXsv1f_.o )
Linking /home/daniel/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_SvXsv1f__3.6.3.0_ghc-9.2.5 ...

<no location info>: error:
    Warning: Couldn't figure out linker information!
             Make sure you're using GNU ld, GNU gold or the built in OS X linker, etc.
collect2: fatal error: cannot find ‘ld’
compilation terminated.
`gcc' failed in phase `Linker'. (Exit code: 1)

Error: [S-6374]
       While building simple Setup.hs (scroll up to its section to see the error) using:
       /home/daniel/.ghcup/ghc/9.2.5/bin/ghc -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.6.3.0 /home/daniel/.stack/setup-exe-src/setup-SvXsv1f_.hs /home/daniel/.stack/setup-exe-src/setup-shim-SvXsv1f_.hs -o /home/daniel/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_SvXsv1f__3.6.3.0_ghc-9.2.5
       Process exited with code: ExitFailure 1 
$ ld --version
GNU ld (GNU Binutils) 2.40
Copyright (C) 2023 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
1 Like

Hello - I was having this issue, which turns out to be tricky mainly because the error message is bad. It turns out that the compiler is not actually looking for ld, but one of a few possible programs. To check this, run ghc --info | grep "\"ld command\"". For me, this gives:

~ $ ghc --info | grep "\"ld command\""
,("ld command","ld.gold")

It’s the file on the right (ld.gold), which needed to exist (at least, in my case). From there, I just created a symlink named ld.gold which pointed to ld in a directory in my PATH. For me, that was ~/.local/bin/:

~ $ ln -s /usr/bin/ld ~/.local/bin/ld.gold

That fixed the issue. I’m not sure if that’s the issue others had, but that’s what I ran into.

1 Like

I’m fairly certain there was a thread somewhere that GHC should not do that (favour particular linker) but rather use whatever PATH’s ld is symlinked to.

Looks like you might have gotten hit by gold just getting removed from the OS package. See [ANN] GHCup 0.1.50.2 release (LD breakage) for details and how to fix if that is the case.

1 Like