`stack test` fails in gcc Linker phase [Fedora linker not working]

Hi everyone !

I’ve just installed GHC and Exercism locally on Fedora 38 (Linux 6.2), and stack test fails in hello-world and other exercises.

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.2.7
$ stack --version
Version 2.9.3, Git revision 6cf638947a863f49857f9cfbf72a38a48b183e7e x86_64 hpack-0.35.1
$ gcc --version
gcc (GCC) 13.0.1 20230401 (Red Hat 13.0.1-0)
...

Found a similar (closed) issue here : `stack test` fails in hello world project · Issue #845 · exercism/haskell · GitHub
I tried stack --resolver lts-14.6 test as suggested and it didn’t work.

Any idea how to fix this ?

Thanks !


Here is the error (had to remove a few lines in the middle cause it made this post too long to be created, hence the [...]) :

[user@fedora hello-world]$ stack test
Linking /home/user/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_SvXsv1f__3.4.1.0_ghc-9.0.2 ...
/usr/bin/ld.gold: error: cannot find -lgmp
/home/user/.ghcup/ghc/9.0.2/lib/ghc-9.0.2/ghc-bignum-1.1/libHSghc-bignum-1.1.a(BigNat.o):function ghczmbignum_GHCziNumziBigNat_bigNatMul_info: error: undefined reference to '__gmpn_mul'
[...]
/home/user/.ghcup/ghc/9.0.2/lib/ghc-9.0.2/ghc-bignum-1.1/libHSghc-bignum-1.1.a(gmp_wrappers.o):gmp_wrappers.c:function integer_gmp_mpn_tdiv_r: error: undefined reference to '__gmpn_tdiv_qr'
collect2: error: ld returned 1 exit status
`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/user/.ghcup/ghc/9.0.2/bin/ghc -rtsopts -threaded -clear-package-db -global-package-db -hide-all-packages -package base -main-is StackSetupShim.mainOverride -package Cabal-3.4.1.0 /home/user/.stack/setup-exe-src/setup-SvXsv1f_.hs /home/user/.stack/setup-exe-src/setup-shim-SvXsv1f_.hs -o /home/user/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_SvXsv1f__3.4.1.0_ghc-9.0.2
       Process exited with code: ExitFailure 1 

The key line seems to be

/usr/bin/ld.gold: error: cannot find -lgmp

Searching for this error yields quite a few results, and adding fedora yields fedora - What should I install to correct "ld: cannot find -lgbm and -linput" so that I can compile a Rust program? - Unix & Linux Stack Exchange. Does that solve your problem?

1 Like

Thanks, I tried sudo dnf install mesa-libgbm-devel
It installed, but I still get the same error :

/usr/bin/ld.gold: error: cannot find -lgmp

Then I have no clue. (I’m on Windows.)

You might want to change the title of the thread, or start a new one. Or ask elsewhere. This is a linker & Fedora probem, not a Haskell one, and many people might not look at threads that look like they are about Haskell.

1 Like

@WQT Did you install GHC through GHCup or through some other means? If the latter, then I recommend you uninstall everything and reinstall using GHCup.

These should be the dependencies: ghcup-hs/install.md at master · haskell/ghcup-hs · GitHub

Ok my bad, when reading the topic linked previously it was about libgbm and not libgmp ! I’m a bit dyslexic so I didn’t see the difference…
So I searched dnf provides '*/libgmp.so', and a simple sudo dnf install gmp-devel fixed it.

For what it’s worth: I’m not dyslexic (probably), but I regularly have similar troubles. Long live copy-paste.

1 Like