🙌

cargo install cargo-generateでハマったときのメモ

2023/05/28に公開

WSL2でcargo-generateを実行しようとしたところ、入ってないと怒られたのでcargo installしたらいろいろハマった。

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/misty1999/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/home/misty1999/.cargo/bin:/home/linuxbrew/.linuxbrew/sbin:/home/linuxbrew/.linuxbrew/bin:/home/misty1999/.rbenv/shims:/home/misty1999/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/WindowsApps/MicrosoftCorporationII.WindowsSubsystemForLinux_1.2.5.0_x64__8wekyb3d8bbwe:/mnt/c/Program Files (x86)/Common Files/Oracle/Java/javapath:/mnt/c/WINDOWS/system32:/mnt/c/WINDOWS:/mnt/c/WINDOWS/System32/Wbem:/mnt/c/WINDOWS/System32/WindowsPowerShell/v1.0/:/mnt/c/WINDOWS/System32/OpenSSH/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/Users/larva/AppData/Local/Microsoft/WindowsApps:/mnt/c/texlive/2021/bin/win32:/mnt/c/Users/larva/AppData/Local/Programs/Microsoft VS Code/bin:/snap/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustcH3RYeN/symbols.o" "/tmp/cargo-installJMgkJn/release/deps/cargo_generate-f7ee458b931eb237.cargo_generate.6a54f4ad-cgu.1.rcgu.o" "-Wl,--as-needed" "-L" "/tmp/cargo-installJMgkJn/release/deps" "-L" "/tmp/cargo-installJMgkJn/release/build/libgit2-sys-faec975835871739/out/build" "-L" "/tmp/cargo-installJMgkJn/release/build/libssh2-sys-8ae217ad748a446f/out/build" "-L" "/home/linuxbrew/.linuxbrew/opt/zlib/lib" "-L" "/home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib" "-L" "/home/misty1999/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/tmp/rustcH3RYeN/liblibgit2_sys-e7f9b6e892bc8993.rlib" "/tmp/rustcH3RYeN/liblibssh2_sys-000ac7b83edbbb8c.rlib" "/home/misty1999/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-957b4aff41f8cd46.rlib" "-Wl,-Bdynamic" "-lssl" "-lcrypto" "-lz" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/home/misty1999/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/tmp/cargo-installJMgkJn/release/deps/cargo_generate-f7ee458b931eb237" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `dladdr@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `dlclose@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `fstat@GLIBC_2.33'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `dlerror@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_key_create@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_rwlock_unlock@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_setspecific@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_rwlock_destroy@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_rwlock_wrlock@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `dlsym@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_getspecific@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_key_delete@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_rwlock_init@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `stat@GLIBC_2.33'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `dlopen@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_once@GLIBC_2.34'
          /usr/bin/ld: /home/linuxbrew/.linuxbrew/Cellar/openssl@1.1/1.1.1t/lib/libcrypto.so: undefined reference to `pthread_rwlock_rdlock@GLIBC_2.34'
          collect2: error: ld returned 1 exit status

  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

error: could not compile `cargo-generate` due to previous error
error: failed to compile `cargo-generate v0.18.3`, intermediate artifacts can be found at `/tmp/cargo-installJMgkJn`

https://github.com/Homebrew/homebrew-core/issues/118825#issuecomment-1423167888
の通りに

brew unlink openssl@1.1

として再度実行したら今度は

  --- stderr
  Package openssl was not found in the pkg-config search path.
  Perhaps you should add the directory containing `openssl.pc'
  to the PKG_CONFIG_PATH environment variable
  No package 'openssl' found

と怒られ。
https://github.com/sfackler/rust-openssl/issues/763
を参考にlibssl-devを入れ、

export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig

としたら解決した。

Discussion