Problems with cross-compiling to raspberry and dependencies/crates

Hello, as far as I can tell my problem is similiar to this one, but the problem in there doesn't really seem solved to me, more avoided. But I'm not sure it is actually a problem with my understanding of rust or with cross-compiling. If it's the latter, I will of course look somewhere else for a solution to my problem.

I tried writing a telegram bot with rust and this crate. The bot is done and now, since I have an old Raspberry Pi (Model B) lying around here, I wanted to deploy it there. So I looked into cross-compiling rust. I am on Windows and used Linux Mint in a vm to cross-compile. I'm not really a linux expert, so maybe the problem lays there? But cross-compiling from windows looked a lot more complicated when I looked at it.
First I added the target with rustup target add arm-unknown-linux-gnueabihf.
Then I followed step 9. from here:

but used the gcc-8 version. And I installed it.
This all works for a simple "Hello World!" project. (Building it with cargo build --target=arm-unknown-linux-gnueabihf)
But when I tried to built my telegram bot I got this error (might be a bit long, I don't know how to put it into a spoiler):

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

Caused by:
  process didn't exit successfully: `/home/wert007/host/rust_tg_chess_bot/target/debug/build/openssl-sys-d03285efbb51f851/build-script-main` (exit code: 101)
 --- stdout
  cargo:rustc-cfg=const_fn
  cargo:rerun-if-env-changed=ARM_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_LIB_DIR
  ARM_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_LIB_DIR
  OPENSSL_LIB_DIR unset
  cargo:rerun-if-env-changed=ARM_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_INCLUDE_DIR
  ARM_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_INCLUDE_DIR
  OPENSSL_INCLUDE_DIR unset
  cargo:rerun-if-env-changed=ARM_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_DIR
  ARM_UNKNOWN_LINUX_GNUEABIHF_OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_DIR
  OPENSSL_DIR unset
  cargo:rerun-if-env-changed=OPENSSL_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_arm-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_arm_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_arm-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_arm_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_arm-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_arm_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  run pkg_config fail: "pkg-config has not been configured to support cross-compilation.\n\n                
  Install a sysroot for the target platform and configure it via\n                
  PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a\n                cross-compiling 
  wrapper for pkg-config and set it via\n                PKG_CONFIG environment variable."

 --- 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-unknown-linux-gnu
  $TARGET = arm-unknown-linux-gnueabihf
  openssl-sys = 0.9.59

I mean I have libssl-dev installed for the host system, but probably not for my target system. And know I'm a little lost what I could do next. I tried building my project on the raspberry, and while all the dependencies get compiled my own project seems to fail.

This is my first time posting here, I hope the formatting is all right, and my english as well.
Thanks for reading until here!

First time also.
Similar problem: cross-compiling from ubuntu to RPi.
I solved it using an explicit dependency to openssl crate (used by reqwest) with feature "vendored" enabled.

#Cargo.toml
[dependencies]
reqwest = { version = "0.10.4", features = ["blocking", "json"] }
...
# Added due to reqwest dependency problems when cross-compiling for RPi
openssl = { version = "0.10.32", features = ["vendored"] }

Found in the Cargo.toml of this crate:

1 Like