2019-07-22 cargo-generate安装失败处理

2022-04-22 17:43:23 浏览数 (1)

cargo install cargo-generate时候出现下面的错误:

代码语言:javascript复制
error: failed to run custom build command for `openssl-sys v0.9.48`

Caused by:
  process didn't exit successfully: `/tmp/cargo-installY8T7i9/release/build/openssl-sys-710a88098f0b790e/build-script-main` (exit code: 101)
--- stdout
cargo:rustc-cfg=const_fn
cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR
X86_64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
OPENSSL_LIB_DIR unset
cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR
X86_64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR
X86_64_UNKNOWN_LINUX_GNU_OPENSSL_DIR unset
cargo:rerun-if-env-changed=OPENSSL_DIR
OPENSSL_DIR unset
run pkg_config fail: "Failed to run `"pkg-config" "--libs" "--cflags" "openssl"`: No such file or directory (os error 2)"

--- stderr
thread 'main' panicked at '

Could not find directory of OpenSSL installation, and this `-sys` crate cannot
proceed without this knowledge. If OpenSSL is installed and this crate had
trouble finding it,  you can set the `OPENSSL_DIR` environment variable for the
compilation process.

Make sure you also have the development packages of openssl installed.
For example, `libssl-dev` on Ubuntu or `openssl-devel` on Fedora.

If you're in a situation where you think the directory *should* be found
automatically, please open a bug at https://github.com/sfackler/rust-openssl
and include information about your system as well as this message.

$HOST = x86_64-unknown-linux-gnu
$TARGET = x86_64-unknown-linux-gnu
openssl-sys = 0.9.48


It looks like you're compiling on Linux and also targeting Linux. Currently this
requires the `pkg-config` utility to find OpenSSL but unfortunately `pkg-config`
could not be found. If you have OpenSSL installed you can likely fix this by
installing `pkg-config`.

', /home/elikong/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.48/build/find_normal.rs:150:5
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

warning: build failed, waiting for other jobs to finish...
error: failed to compile `cargo-generate v0.3.0`, intermediate artifacts can be found at `/tmp/cargo-installY8T7i9`

Caused by:
  build failed

解决方法,参考ChainX 搭建

代码语言:javascript复制
# sudo apt install openssl
# which openssl
/usr/bin/openssl
# ldd /usr/bin/openssl
        linux-vdso.so.1 (0x00007fffc121a000)
        libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007fa72fe20000)
        libcrypto.so.1.1 => /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 (0x00007fa72f950000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa72f730000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa72f330000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa72f120000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fa730400000)
#

通过libssl.so.1.1 => /usr/lib/x86_64-linux-gnu/libssl.so.1.1 (0x00007fa72fe20000)知道OPENSSL_LIB_DIR是 /usr/lib/x86_64-linux-gnu

代码语言:javascript复制
# find / -name "openssl" | grep include
find: /usr/include/openssl

知道OPENSSL_INCLUDE_DIR是/usr/include/openssl 编辑.bashrc,添加:

代码语言:javascript复制
export OPENSSL_INCLUDE_DIR=/usr/include/openssl
export OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu

然后

代码语言:javascript复制
source ~/.bashrc
cargo install cargo-generate

这个时候就可以成功

0 人点赞