为什么即使在本地安装后,rust 也无法为 openssl-sys v0.9.60 构建命令?
Why rust is failing to build command for openssl-sys v0.9.60 even after local installation?
我在尝试构建我的 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
returns /usr/local/bin/openssl
.
我还安装了 pkg-config(如 中所建议)。 运行 which pkg-config
returns /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。事实上,我的PC中有一个/usr/local/ssl
文件夹,但那里没有lib
。
我在这里做错了什么?如何让我本地安装的 openssl 正确地与 rust 一起工作?
我自己没有安装这个的经验,但可以提供一些指导。
首先是关于您安装 OpenSSL 的努力。克隆存储库后,在配置和制作之前,您不需要 select 任何特定的分支。这意味着您正在构建 master
分支,它是 OpenSSL 3.0.0 的进化版本。根据 the crate's documentation. In order to build a supported version of OpenSSL, you will have to switch to some 1.1.1 branch or tag. Alternatively, you can download the 1.1.1 version from OpenSSL's download page.
,这不是受支持的版本
也就是说,似乎没有必要从源代码安装 OpenSSL。在 Automatic 部分下,文档解释说这个箱子可以处理各种典型的 OpenSSL 安装。如果可能的话,您可能更容易遵循这一点。如果是这样,那么您应该取消设置 OPENSSL_DIR
环境变量,否则将(继续)覆盖 crate 的自动机制以查找 OpenSSL 安装。
如果您仍想坚持使用 Manual configuration, then indeed you should use environment variables, and OPENSSL_DIR
seems a convenient one. However, it does not mean the same thing as the openssldir
parameter that you used in your configure command ./config --openssldir=/usr/local/ssl
. To get the details, check out the meaning of that configuration parameter. In fact, the crate's meaning of OPENSSL_DIR
corresponds to the --prefix
setting(您没有配置)。
您 运行 现在遇到的问题是您的 OPENSSL_DIR
变量指向您的 OpenSSL 配置文件目录,而 crate 期望它指向实际 OpenSSL 安装目录的顶部树(在您的情况下似乎位于 /usr/local
)。
将变量 openssl_dir 设置为合适的 PATH
运行 :
sudo apt install pkg-config
这为我解决了 Ubuntu 中的问题:
sudo apt install libssl-dev
我使用了下面的一组命令
sudo apt install pkg-config
sudo apt-get install libudev-dev
我在 Windows 上的 Ubuntu 上使用了以下命令:
sudo apt install libudev-dev
sudo apt install libssl-dev
我在尝试构建我的 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
returns /usr/local/bin/openssl
.
我还安装了 pkg-config(如 which pkg-config
returns /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。事实上,我的PC中有一个/usr/local/ssl
文件夹,但那里没有lib
。
我在这里做错了什么?如何让我本地安装的 openssl 正确地与 rust 一起工作?
我自己没有安装这个的经验,但可以提供一些指导。
首先是关于您安装 OpenSSL 的努力。克隆存储库后,在配置和制作之前,您不需要 select 任何特定的分支。这意味着您正在构建 master
分支,它是 OpenSSL 3.0.0 的进化版本。根据 the crate's documentation. In order to build a supported version of OpenSSL, you will have to switch to some 1.1.1 branch or tag. Alternatively, you can download the 1.1.1 version from OpenSSL's download page.
也就是说,似乎没有必要从源代码安装 OpenSSL。在 Automatic 部分下,文档解释说这个箱子可以处理各种典型的 OpenSSL 安装。如果可能的话,您可能更容易遵循这一点。如果是这样,那么您应该取消设置 OPENSSL_DIR
环境变量,否则将(继续)覆盖 crate 的自动机制以查找 OpenSSL 安装。
如果您仍想坚持使用 Manual configuration, then indeed you should use environment variables, and OPENSSL_DIR
seems a convenient one. However, it does not mean the same thing as the openssldir
parameter that you used in your configure command ./config --openssldir=/usr/local/ssl
. To get the details, check out the meaning of that configuration parameter. In fact, the crate's meaning of OPENSSL_DIR
corresponds to the --prefix
setting(您没有配置)。
您 运行 现在遇到的问题是您的 OPENSSL_DIR
变量指向您的 OpenSSL 配置文件目录,而 crate 期望它指向实际 OpenSSL 安装目录的顶部树(在您的情况下似乎位于 /usr/local
)。
将变量 openssl_dir 设置为合适的 PATH
运行 :
sudo apt install pkg-config
这为我解决了 Ubuntu 中的问题:
sudo apt install libssl-dev
我使用了下面的一组命令
sudo apt install pkg-config
sudo apt-get install libudev-dev
我在 Windows 上的 Ubuntu 上使用了以下命令:
sudo apt install libudev-dev
sudo apt install libssl-dev