在 wsl CentOS 8 上使用 `stack build` 时出现链接错误

问题描述 投票:0回答:1

运行时遇到以下问题

stack build

[3 of 3] Linking .stack-work/dist/x86_64-linux/ghc-9.6.6/build/cap/cap
/usr/bin/ld.gold: error: cannot find -ltinfo
/usr/bin/ld.gold: error: cannot find -lgmp
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/haskeline-0.8.2.1/libHShaskeline-0.8.2.1.a(Terminfo.o)(.text+0x20efe): error: undefined reference to 'set_curterm'
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/haskeline-0.8.2.1/libHShaskeline-0.8.2.1.a(Terminfo.o)(.text+0x21012): error: undefined reference to 'set_curterm'
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/haskeline-0.8.2.1/libHShaskeline-0.8.2.1.a(Terminfo.o)(.text+0x210a4): error: undefined reference to 'set_curterm'
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/haskeline-0.8.2.1/libHShaskeline-0.8.2.1.a(Terminfo.o)(.text+0x2113c): error: undefined reference to 'set_curterm'
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/ghc-bignum-1.3/libHSghc-bignum-1.3.a(BigNat.o):function ghczmbignum_GHCziNumziBigNat_bigNatEqzh_info: error: undefined reference to '__gmpn_cmp'
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/ghc-bignum-1.3/libHSghc-bignum-1.3.a(BigNat.o):function ghczmbignum_GHCziNumziBigNat_bigNatQuotWordzh_info: error: undefined reference to '__gmpn_divrem_1'
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/ghc-bignum-1.3/libHSghc-bignum-1.3.a(BigNat.o):function ghczmbignum_GHCziNumziBigNat_bigNatQuotRemWordzh_info: error: undefined reference to '__gmpn_divrem_1'
...
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/ghc-bignum-1.3/libHSghc-bignum-1.3.a(gmp_wrappers.o):function integer_gmp_mpn_xor_n: error: undefined reference to '__gmpn_xor_n'
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/rts-1.0.2/libHSrts-1.0.2_thr.a(Linker.thr_o):Linker.c:function internal_dlopen: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/home/%username%/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/x86_64-linux-ghc-9.6.6/rts-1.0.2/libHSrts-1.0.2_thr.a(Elf.thr_o):Elf.c:function loadNativeObj_ELF: warning: Using 'dlopen' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib64/libpthread.a(libpthread.o)(.note.stapsdt+0x31c): warning: relocation refers to discarded section
/usr/lib64/libpthread.a(libpthread.o)(.note.stapsdt+0x378): warning: relocation refers to discarded section
/usr/lib64/libpthread.a(libpthread.o)(.note.stapsdt+0x3d0): warning: relocation refers to discarded section
/usr/lib64/libpthread.a(libpthread.o)(.note.stapsdt+0x428): warning: relocation refers to discarded section
collect2: error: ld returned 1 exit status
ghc-9.6.6: `gcc' failed in phase `Linker'. (Exit code: 1)

Error: [S-7282]
       Stack failed to execute the build plan.

       While executing the build plan, Stack encountered the error:

       [S-7011]
       While building package cap-1.0.1 (scroll up to its section to see the error) using:
       /home/%username%/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_DY68M0FN_3.10.3.0_ghc-9.6.6 --verbose=1 --builddir=.stack-work/dist/x86_64-linux/ghc-9.6.6 build lib:cap exe:cap --ghc-options " -fdiagnostics-color=always"
       Process exited with code: ExitFailure 1

堆栈版本为3.1.1。 ghc版本是9.6.6。操作系统是 CentOS 8。

我认为问题是由于找不到路径而发生的。所以我像这样添加了 --ghc-options 的路径

stack build --ghc-options " -L/usr/lib64 "

我测试链接时效果很好

[l00575070@DESKTOP-D3VERKP CAP]$ ld.gold -ltinfo --verbose -L/usr/lib64
ld.gold: Opened new descriptor 3 for "/usr/lib64/libtinfo.so"
ld.gold: Attempt to open /usr/lib64/libtinfo.so succeeded
ld.gold: Unlocking file "/usr/lib64/libtinfo.so"
ld.gold: Released descriptor 3 for "/usr/lib64/libtinfo.so"
ld.gold: Opened new descriptor 5 for "a.out"

但是同样的问题仍然存在。我该如何解决这个问题?

linker haskell-stack
1个回答
0
投票

没关系。我发现系统虽然包含tinfo/gmp的.so,但不包含.a文件。我为两个库都添加了.a,问题就解决了。

© www.soinside.com 2019 - 2024. All rights reserved.