100

I'm facing the error failed to run custom build command for openssl-sys v0.9.60 while trying to build my rust program. Here are the main.rs and the Cargo.toml files.

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"

I installed openssl locally (as suggested in this question), using:

git clone git://git.openssl.org/openssl.git
cd openssl
./config --openssldir=/usr/local/ssl
make
make test
sudo make install

Finally, I ran export OPENSSL_DIR="/usr/local/ssl"

I noted I already had a anaconda instalation of openssl which was in my default path. To change the default path of openssl to the github instalation I ran chmod -x MYPATH/anaconda3/bin/openssl and now which openssl returns /usr/local/bin/openssl.

I also have pkg-config installed (as suggested in this question). Running which pkg-config returns /usr/bin/pkg-config

However, when I run cargo run again the program print the same error message. Here is the entire error message:

> 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

It looks like that rust is searching for ssl in /usr/local/ssl/lib. In fact, there is a /usr/local/ssl folder in my PC, but there is no lib there.

What am I doing wrong here? How can make my local installation of openssl work with rust correctly?

3
  • 2
    stackoverflow.com/a/70635680/14009899 sudo apt install libssl-dev worked for me Commented Aug 8, 2022 at 6:27
  • 2
    I wrote up an issue for this here github.com/sfackler/rust-openssl/issues/1865 - my workaround was to use the "feature=vendored" mentioned in comments to answers below. Commented Mar 30, 2023 at 23:04
  • I was able to do the same: openssl = { version = "0.10", features = ["vendored"] } Commented Jan 6 at 0:38

18 Answers 18

97

This solved the issue for me in Ubuntu:

sudo apt install libssl-dev
Sign up to request clarification or add additional context in comments.

6 Comments

for fedora/cantos it's yum install openssl openssl-devel -y
This is the most specific correct answer for debian and derivative distros. Crate openssl-sys should document their dependency on the developer bindings for openssl. See github.com/sfackler/rust-openssl/issues/1759.
can confirm it works on debian 12 (bullseye) as of jul 2023.
We also needed to run sudo apt install pkg-config on Ubuntu Jammy (22.04).
I don't know why but installing both openssl-devel and pkg-config didn't solve the problem for me on Oracle Linux 9 (a CentOS-like distro) with Rust 1.83 nightly...
|
37

I used the following set of commands

 sudo apt install pkg-config
 sudo apt-get install libudev-dev

Comments

18

I have no experience with installing this myself but may be able to give some pointers.

First of all about your effort to install OpenSSL. After cloning the repository, you do not select any particular branch before configuring and making. This means that you are building the master branch, which is an evolving version of OpenSSL 3.0.0. This is not a supported version according to 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.

That said, it does not seem necessary to install OpenSSL from source. Under the section Automatic, the documentation explains that the crate can deal with all kinds of typical OpenSSL installations. It may be easier for you to follow that, if possible in your case. If so, then you should unset the OPENSSL_DIR environment variable otherwise that will (continue to) override the crate's automatic mechanisms to find the OpenSSL installation.

If you still want to stick with the 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 (which you did not configure).

The problem you are running into now is that your OPENSSL_DIR variable points to your directory for OpenSSL configuration files, whereas the crate expects it to point to the top of the actual OpenSSL installation directory tree (which in your case seems to reside at /usr/local).

5 Comments

I didn't realize at the time the full implication of what you said. But for automatic installation it is sufficient add openssl = { version = "0.10", features = ["vendored"] } to Cargo.toml.
This might not be sufficient. In my case, I already had libssl-dev installed, but, for reasons unknown, in a different laptop (with a fresh Ubuntu 22.04 LTS install) it'd still run into a similar issue. Here, the reqwest crate was the culprit and you have to set default-features = false and add rustls-tls-native-roots to the features list in the Cargo.toml file to get it to use a pure Rust TLS implementation and avoid other system library-specific issues.
@Lucas was a lifesaver. The most useful answer here was a comment. I was hitting this issue with rust-bert's convert-tensor script, that executes a cargo-built binary. Needed to slip that into the Cargo.toml so it'd load an openssl version that wouldn't fail.
@Lucas your comment worked for me, it might be good to turn this into a proper answer so I can upvote it. Finally got a green build: github.com/timabell/gitopolis/actions/runs/4552699507/jobs/… Thank you!
... the reason "features = vendored" works is because it toggles a "feature" of the openssl crate that causes it to build openssl from the C source instead of looking for the shared library (which for some reason isn't being found) - docs.rs/openssl/latest/openssl/#vendored
16

On fedora 36 I was getting error: failed to run custom build command for openssl-sys v0.9.77 when trying to install cargo-generate using cargo install cargo-generate

openssl-devel and pkg-config were already installed.

There was another complain below the main one:

Can't locate FindBin.pm in @INC (you may need to install the FindBin module) (@INC contains: /usr/local/lib64/perl5/5.34 /usr/local/share/perl5/5.34 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at ./Configure line 15.

The solution was:

sudo dnf install perl

Surprisingly, perl was already installed but by running sudo dnf install perl "some additional perl stuff" got installed which resolved the issue!

4 Comments

this worked for me. really weird but I'll take it. @Mamad any ideas on why this was the case?
@ArjunPatel I'm not entirely sure, perl was already installed but by running sudo dnf install perl "some additional perl stuff" got installed which ultimately resolved the issue!
No logic in this move, but it works. Helped to build Rust on Amazon Linux 3 (arm64).
This is witchcraft, for sure. Thanks!
14

I ran rust on Windows Subsystem for Linux (Ubuntu). The following commands have worked for me.

sudo apt install libssl-dev

sudo apt install pkg-config

Comments

13

Just to add more information from source openssl crate docs

# macOS (Homebrew)
$ brew install openssl@3

# macOS (MacPorts)
$ sudo port install openssl

# macOS (pkgsrc)
$ sudo pkgin install openssl

# Arch Linux
$ sudo pacman -S pkg-config openssl

# Debian and Ubuntu
$ sudo apt-get install pkg-config libssl-dev

# Fedora
$ sudo dnf install pkg-config perl-FindBin openssl-devel

# Alpine Linux
$ apk add pkgconfig openssl-dev

# openSUSE
$ sudo zypper in libopenssl-devel

2 Comments

On Fedora now at least, perl-FindBin is insufficient: I had to install perl-IPC-Cmd too, but that is also insufficient, but installing perl seems to pull in all needed perl deps.
Also had to install today "systemd-devel" on Fedora.
8

To all the orphans left behind by Unclesoft stuck with Windows:

cargo build
    Updating crates.io index
Compiling openssl-sys v0.9.95
error: failed to run custom build command for `openssl-sys v0.9.95`

Caused by:
process didn't exit successfully: `D:\dev\samples\rust\kafka_demo\target\debug\build\openssl-sys-c2690b7cfe32b0fd\build-script-main` (exit code: 101)
... OPENSSL_INCLUDE_DIR unset
cargo:rerun-if-env-changed=X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR
X86_64_PC_WINDOWS_MSVC_OPENSSL_DIR unset

To fix, steps below, but they take a long time (~1hr): How to work with OpenSSL for Rust within a Windows development environment

clone vcpkg https://github.com/Microsoft/vcpkg
open directory where you've cloned vcpkg
run ./bootstrap-vcpkg.bat
run ./vcpkg.exe install openssl-windows:x64-windows
run ./vcpkg.exe install openssl:x64-windows-static
run ./vcpkg.exe integrate install
run set VCPKGRS_DYNAMIC=1 (or simply set it as your environment variable)

Comments

4

run :

sudo apt install pkg-config

Comments

3

I found that upgrading the version to 0.10 and adding features = ["vendored"] was consistent for me. Try adding this in Cargo.toml

openssl = { version = "0.10", features = ["vendored"] }

1 Comment

This is the answer on most systems
2

I used the following commands on Ubuntu on Windows:

 sudo apt install libudev-dev
 sudo apt install libssl-dev

Comments

2

this worked for me:

sudo apt install librust-openssl-sys-dev

Comments

2

On Ubuntu 22.04 I had a different issue associated with this error:

run pkg_config fail: "\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\" did not exit successfully: exit status: 1

error: could not find system library 'openssl' required by the 'openssl-sys' crate

--- 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"

I had already installed libssl-devel and pkg-config.

I solved this by searching for openssl.pc, which was located in /usr/lib/x86_64-linux-gnu/pkgconfig/openssl.pc.

I could solve it by setting PKG_CONFIG_PATH to /usr/lib/x86_64-linux-gnu/pkgconfig/ manually.

Comments

2

I encounterd this issue today. I'm not sure how and which Cargo.toml to add the "features = vendored". Finally, I set some enviroment variables of Openssl and it works.

OPENSSL_DIR=/usr/
OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu/

You can check the exact path of openssl by running the following command: dpkg -L libssl-dev

1 Comment

For detail path of Openssl, you can refer to docs.rs/openssl/0.10.32/openssl/#manual
1

On Fedora 39 in Jan 2024 - I had to run this:

sudo dnf install -y openssl openssl-libs openssl-devel pkg-config perl

1 Comment

openssl-devel by itself already pulls in openssl-libs and pkgconf - I doubt openssl is needed. ie perl + openssl-devel should be sufficient
0

if 'sudo apt install libssl-dev' and 'sudo apt install pkg-config' are already installed just run 'sudo apt update' and then restart the vscode. This worked for me.

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0

I was building it on WSL, so cargo build --release was successful, but cargo lambda build --release --output-format zip was failing even though everything has been installed. Another problem was that building openssl-sys will be stuck for 30-40 minutes without any progress.

So, in my case I have decided to move away from openssl and use rustls instead.

By running cargo tree -i openssl I have discovered that it was the reqwest library that used openssl.

cargo-tree-output

So, in order to remove the dependency on openssl, I have modified Cargo.toml as follows:

[dependencies]
reqwest = { version = "0.12.12", default-features = false, features = ["rustls-tls"] }

After applying that change I have been able to build the solution by using cargo lambda.

Comments

-1

Make sure that the make command is installed, it is not always pre-installed. You can run :

sudo apt-get install build-essential

This solved the problem in my case.

Comments

-1

WINDOWS

choco install openssl
$env:OPENSSL_DIR = "C:\Program Files\OpenSSL-Win64";
$env:OPENSSL_STATIC = "true";

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.