haskell-ide-engineで ld: symbol(s) not found for architecture x86_64 のエラーが出る
vscode と haskell-ide-engine で Haskell 開発環境を構築する - Qiita
をもとに環境構築を進めていたところ以下のエラーが出て、haskell-ide-engineをmake
することができませんでした。
❯ make hie-8.6.3 (中略) cabal-install-2.4.1.0: configure Completed 19 action(s). -- While building package cabal-install-2.4.1.0 using: /Users/cipepser/.stack/programs/x86_64-osx/ghc-8.6.3/bin/ghc --make -odir /private/var/folders/mc/3v_pttq16pdblh7vbqf4mvk80000gn/T/stack33371/cabal-install-2.4.1.0/.stack-work/dist/x86_64-osx/Cabal-2.4.0.1/setup -hidir /private/var/folders/mc/3v_pttq16pdblh7vbqf4mvk80000gn/T/stack33371/cabal-install-2.4.1.0/.stack-work/dist/x86_64-osx/Cabal-2.4.0.1/setup -i -i. -clear-package-db -global-package-db -package-db=/Users/cipepser/.stack/snapshots/x86_64-osx/nightly-2018-12-31/8.6.3/pkgdb -package-db=/Users/cipepser/hie/haskell-ide-engine/.stack-work/install/x86_64-osx/nightly-2018-12-31/8.6.3/pkgdb -hide-all-packages -package-id=Cabal-2.4.1.0-IaB5GUEm19R82R9cEdbB1D -package-id=base-4.12.0.0 -package-id=filepath-1.4.2.1 -package-id=process-1.6.3.0 -optP-include -optP/private/var/folders/mc/3v_pttq16pdblh7vbqf4mvk80000gn/T/stack33371/cabal-install-2.4.1.0/.stack-work/dist/x86_64-osx/Cabal-2.4.0.1/setup/setup_macros.h /private/var/folders/mc/3v_pttq16pdblh7vbqf4mvk80000gn/T/stack33371/cabal-install-2.4.1.0/Setup.hs /Users/cipepser/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs -main-is StackSetupShim.mainOverride -o /private/var/folders/mc/3v_pttq16pdblh7vbqf4mvk80000gn/T/stack33371/cabal-install-2.4.1.0/.stack-work/dist/x86_64-osx/Cabal-2.4.0.1/setup/setup -threaded Process exited with code: ExitFailure 1 Logs have been written to: /Users/cipepser/hie/haskell-ide-engine/.stack-work/logs/cabal-install-2.4.1.0.log [1 of 2] Compiling Main ( /private/var/folders/mc/3v_pttq16pdblh7vbqf4mvk80000gn/T/stack33371/cabal-install-2.4.1.0/Setup.hs, /private/var/folders/mc/3v_pttq16pdblh7vbqf4mvk80000gn/T/stack33371/cabal-install-2.4.1.0/.stack-work/dist/x86_64-osx/Cabal-2.4.0.1/setup/Main.o ) [2 of 2] Compiling StackSetupShim ( /Users/cipepser/.stack/setup-exe-src/setup-shim-mPHDZzAJ.hs, /private/var/folders/mc/3v_pttq16pdblh7vbqf4mvk80000gn/T/stack33371/cabal-install-2.4.1.0/.stack-work/dist/x86_64-osx/Cabal-2.4.0.1/setup/StackSetupShim.o ) Linking /private/var/folders/mc/3v_pttq16pdblh7vbqf4mvk80000gn/T/stack33371/cabal-install-2.4.1.0/.stack-work/dist/x86_64-osx/Cabal-2.4.0.1/setup/setup ... clang-7: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument] clang-7: warning: argument unused during compilation: '-nopie' [-Wunused-command-line-argument] ld: warning: ignoring file /Users/cipepser/.stack/snapshots/x86_64-osx/nightly-2018-12-31/8.6.3/lib/x86_64-osx-ghc-8.6.3/Cabal-2.4.1.0-IaB5GUEm19R82R9cEdbB1D/libHSCabal-2.4.1.0-IaB5GUEm19R82R9cEdbB1D.a, file was built for archive which is not the architecture being linked (x86_64): /Users/cipepser/.stack/snapshots/x86_64-osx/nightly-2018-12-31/8.6.3/lib/x86_64-osx-ghc-8.6.3/Cabal-2.4.1.0-IaB5GUEm19R82R9cEdbB1D/libHSCabal-2.4.1.0-IaB5GUEm19R82R9cEdbB1D.a Undefined symbols for architecture x86_64: "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziSetup_replDistPref_closure", referenced from: _s8sM_info in StackSetupShim.o _u8AR_srt in StackSetupShim.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziSetup_replVerbosity_closure", referenced from: _s8sZ_info in StackSetupShim.o _u8AT_srt in StackSetupShim.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziBuild_initialBuildSteps_closure", referenced from: _c8y6_info in StackSetupShim.o _u8AV_srt in StackSetupShim.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimple_defaultMainWithHooks_closure", referenced from: _s7o5_info in Main.o _s7o5_closure in Main.o _c8DE_info in StackSetupShim.o _u8EF_srt in StackSetupShim.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziUserHooks_replHook_closure", referenced from: _c8xN_info in StackSetupShim.o _c8y1_info in StackSetupShim.o _u8AW_srt in StackSetupShim.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimple_simpleUserHooks_closure", referenced from: _s7qo_info in Main.o _u7FE_srt in Main.o _c8xN_info in StackSetupShim.o _c8y1_info in StackSetupShim.o _s8u9_info in StackSetupShim.o _u8AW_srt in StackSetupShim.o _u8EE_srt in StackSetupShim.o ... "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziSetup_buildVerbosity_closure", referenced from: _s7p9_info in Main.o _u7Fs_srt in Main.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziUtils_installOrdinaryFiles_closure", referenced from: _r3TL_info in Main.o _r3TL_closure in Main.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziSetup_copyVerbosity_closure", referenced from: _s7pN_info in Main.o _u7Fv_srt in Main.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziSetup_copyDest_closure", referenced from: _s7q1_info in Main.o _u7Fx_srt in Main.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziLocalBuildInfo_absoluteInstallDirs_closure", referenced from: _s7nU_info in Main.o _u7wv_srt in Main.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziUtils_notice_closure", referenced from: _s7pm_info in Main.o _u7Fj_srt in Main.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziInstallDirs_NoCopyDest_closure", referenced from: _s7qn_info in Main.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziTypesziHookedBuildInfo_emptyHookedBuildInfo_closure", referenced from: _s8tV_info in StackSetupShim.o _u8EB_srt in StackSetupShim.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziUserHooks_UserHooks_con_info", referenced from: _c7xB_info in Main.o _c8DN_info in StackSetupShim.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziSetup_installVerbosity_closure", referenced from: _s7ql_info in Main.o _u7FA_srt in Main.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziInstallDirs_mandir_closure", referenced from: _s7nV_info in Main.o _u7ww_srt in Main.o "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziSimpleziFlag_fromFlag_closure", referenced from: _s7qk_info in Main.o _s7q0_info in Main.o _s7pM_info in Main.o _s7p8_info in Main.o _u7Fr_srt in Main.o _s8t0_info in StackSetupShim.o _s8sN_info in StackSetupShim.o ... "_Cabalzm2zi4zi1zi0zmIaB5GUEm19R82R9cEdbB1D_DistributionziTypesziLocalBuildInfo_buildDir_closure", referenced from: _s7nY_info in Main.o _s7pb_info in Main.o _s7pe_info in Main.o _u7wz_srt in Main.o _u7Fo_srt in Main.o ld: symbol(s) not found for architecture x86_64 clang-7: error: linker command failed with exit code 1 (use -v to see invocation) `clang' failed in phase `Linker'. (Exit code: 1) make: *** [cabal] Error 1
2019年1月末時点で、同じようなエラーでissueがいくつも立てられて(特にOSXで......)います。 ワークアラウンドも様々なようなので、今回は自分が解消した方法を残します。
環境、ビルド対象
OS
システムのバージョン: macOS Mojave 10.14.3 (18D42) カーネルのバージョン: Darwin 18.2.0
haskell-ide-engine
ビルド対象のcommit: d9bcbf28408da4c42e54cfd5014cfc1cce3ca993
なお、Makefile
中で指定されているようにcabal
のバージョンは2.4.1.0
です。
brew
念のため。
❯ brew --version Homebrew 2.0.0 Homebrew/homebrew-core (git revision 175af; last commit 2019-02-02) Homebrew/homebrew-cask (git revision 05a81; last commit 2019-02-02)
解決策
Build failed on MacOS with clang link error(ghc 8.4.4) · Issue #1058 · haskell/haskell-ide-engineに書いてあるとおり、別プロジェクトでインストールしていたbinutils
が悪さをしていたようです。unlink
したところ、うまくいきました。
※ issueではghc 8.4.4
ですが、8.6.3
でも同じ方法で解決しました。
❯ brew unlink binutils Unlinking /usr/local/Cellar/binutils/2.31.1_2... 120 symlinks removed ❯ rm -rf ~/.stack ❯ stack clean --full
stack clean
はrm
の先にやってもいいかもしれないです。
この状態で、make hie-8.6.3
したらエラーが解消され、以下のようにhie
がインストールできました。
❯ hie --version Version 0.5.0.0, Git revision d9bcbf28408da4c42e54cfd5014cfc1cce3ca993 (2394 commits) x86_64 ghc-8.6.3
なお、後続のmake build-doc-8.6.3
も問題なくビルドできました。
その他
Makefileのどのコマンドで失敗していたか
cabal: stack install cabal-install cabal update cabal install Cabal-2.4.1.0 --with-compiler=$(GHC) .PHONY: cabal
ここのstack install cabal-install
で冒頭のエラーとなっていました。