【发布时间】:2021-01-03 18:41:59
【问题描述】:
我在尝试构建我的 rust 程序时遇到错误 failed to run custom build command for openssl-sys v0.9.60。这是main.rs 和Cargo.toml 文件。
main.rs
extern crate reqwest;
fn main() {
let mut resp = reqwest::get("http://www.governo.mg.gov.br/Institucional/Equipe").unwrap();
assert!(resp.status().is_success());
}
Cargo.toml
[package]
name = "get_sct"
version = "0.1.0"
authors = ["myname <myemail>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
reqwest = "0.10.10"
我在本地安装了 openssl(如 question 中所建议的那样),使用:
git clone git://git.openssl.org/openssl.git
cd openssl
./config --openssldir=/usr/local/ssl
make
make test
sudo make install
最后,我跑了export OPENSSL_DIR="/usr/local/ssl"
我注意到我已经在我的默认路径中安装了 openssl 的 anaconda。要将 openssl 的默认路径更改为 github 安装,我运行了 chmod -x MYPATH/anaconda3/bin/openssl,现在 which openssl 返回 /usr/local/bin/openssl。
我还安装了 pkg-config(如 question 中所建议的那样)。运行which pkg-config 返回/usr/bin/pkg-config
但是,当我再次运行 cargo run 时,程序会打印相同的错误消息。以下是完整的错误信息:
> cargo run
Compiling openssl-sys v0.9.60
Compiling tokio v0.2.24
Compiling pin-project-internal v0.4.27
Compiling pin-project-internal v1.0.2
Compiling mime_guess v2.0.3
Compiling url v2.2.0
error: failed to run custom build command for `openssl-sys v0.9.60`
Caused by:
process didn't exit successfully: `/PACKAGEPATH/target/debug/build/openssl-sys-db18d493257de4f7/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 = /usr/local/ssl
--- stderr
thread 'main' panicked at 'OpenSSL library directory does not exist: /usr/local/ssl/lib', /home/lucas/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.60/build/main.rs:66:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build faile
看起来 rust 正在/usr/local/ssl/lib 中搜索 ssl。其实我的电脑里有一个/usr/local/ssl文件夹,但是那里没有lib。
我在这里做错了什么?如何让我的本地安装的 openssl 正确使用 rust?
【问题讨论】: