Error build Rust for linux in macos - Openssl
Asked Answered
H

3

8

Trying to compile for linux from a mac throws this error, I have openssl and pkg-config installed from brew.

And in the file ~/.cargo/config I have this configuration.

[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"

Error:

error: failed to run custom build command for `openssl-sys v0.9.72`

Caused by:
  process didn't exit successfully: `/Users/Proyect/cvm/target/release/build/openssl-sys-66182f9fe15cdddc/build-script-main` (exit status: 101)
  run pkg_config fail: "`\"pkg-config\" \"--libs\" \"--cflags\" \"openssl\"` did not exit successfully: exit status: 1\nerror: could not find system library 'openssl' required by the 'openssl-sys' crate\n\n--- stderr\nPackage openssl was not found in the pkg-config search path.\nPerhaps you should add the directory containing `openssl.pc'\nto the PKG_CONFIG_PATH environment variable\nNo package 'openssl' found\n"

  --- 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-apple-darwin
  $TARGET = x86_64-unknown-linux-gnu
  openssl-sys = 0.9.72

  ', /Users/user/.cargo/registry/src/github.com-1ecc6299db9ec823/openssl-sys-0.9.72/build/find_normal.rs:180:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
error: build failed
Houseclean answered 2/3, 2022 at 3:55 Comment(5)
Does this answer your question? OpenSSL crate fails compilation on Mac OS X 10.11Mouseear
I tried all the answers in that thread but none of them worked for me, that's why I created this one :(.Houseclean
See also: #63427259Mouseear
FWIW, the target in your cargo config is x86_64-unknown-linux-musl, but the target in the error message is x86_64-unknown-linux-gnu.Hookah
Works for Ubuntu - github.com/rust-lang/rls/issues/250Upsurge
B
11

The error message contains three possible solutions:

First make sure it is really installed including for development (which is what you need if you want to compile code against openssl):

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

If it is already really installed, then it could not be found. This can be fixed by adding the directory containing `openssl.pc' to the PKG_CONFIG_PATH environment variable:

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.

Or by setting the OPENSSL_DIR to point to where the openssl code is on your system:

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.

Blasting answered 2/3, 2022 at 17:53 Comment(2)
I have done all those configurations but it keeps throwing me the same error, it is in the line openssl-sys-0.9.72/build/find_normal.rs:180:5, it gives me the impression that it needs some openssl that is precompiled for linux.Houseclean
If you're cross-compiling, you need to install openssl-dev for the target system, not the host system, and point PKG_CONFIG_PATH to this target install.Mouseear
Z
0

I had to set/export these openssl (brew installed) directories on Mac trying to compile a AWS Lambda Rust function:

export OPENSSL_LIB_DIR=/usr/local/opt/openssl/bin/openssl export OPENSSL_DIR=/usr/local/opt/openssl/bin/openssl export OPENSSL_LIB_DIR=/usr/local/opt/openssl/lib

This is part of the error message I was getting to hopefully help the coders still using Google in 2023:

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
Zahn answered 21/3, 2023 at 8:42 Comment(0)
K
-4

try add

[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"

to your Cargo.toml

Kiona answered 14/9, 2022 at 5:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.