Avatar ·

Rust中openssl-sys构建错误:即使安装了OpenSSL也无法解决问题的方案

大家好!我是Rust新手,正在尝试构建一个使用`openssl` crate的项目。我通过包管理器本地安装了OpenSSL(在Ubuntu上执行了`sudo apt install libssl-dev`),但在运行`cargo build`时遇到了错误: ``` error: failed to run custom build command for `openssl-sys v0.9.60` Caused by: process didn't exit successfully: `/path/to/target/debug/build/openssl-sys-...` (exit status: 101) --- stderr run pkg_config fail: "Could not run `\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"`" ``` 我确认`libssl-dev`已安装,重启了终端,甚至重新安装了Rust——但都没有用。Rust版本:1.65.0,Cargo:最新版。这是我的`Cargo.toml`: ```toml [dependencies] openssl = "0.10.45" ``` 请问问题可能出在哪里?为什么`openssl-sys`找不到已安装的库,尽管它确实存在?我还尝试安装了`pkg-config`——错误依然存在。是不是需要在环境变量中设置什么?