Error on cross compiling project with alsa crate

I try to crosscompile a project using the midir alsa crate. My build command is PKG_CONFIG_ALLOW_CROSS=1 cargo build --target=armv7-unknown-linux-gnueabihf. Unfortunately i get this error just by adding the crate to my cargo.toml file:

error: linking with `arm-linux-gnueabihf-gcc` failed: exit code: 1
  |
  = note: "arm-linux-gnueabihf-gcc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-L"
[...]
"-Wl,-Bdynamic" "-ldl" "-lrt" "-lpthread" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-lutil" "-lutil"
  = note: /usr/lib/libdl.so: file not recognized: file format not recognized
          collect2: error: ld returned 1 exit status

Im on an archlinux with latest arm-linux-gnueabihf-gcc installed. I installed the armv7-unknown-linux-gnueabihf via rustup. I put a config file in the .cargo folder with the following content:

[target.armv7-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"

All dependencies compile without a problem (except the alsa-sys crate needs PKG_CONFIG_ALLOW_CROSS=1 to crosscompile) but in the end my project fails compiling. Has someone an idea what the problem is?

PKG_CONFIG_ALLOW_CROSS=1 exists as a warning that pkg-config does not support cross-compilation.

pkg-config searches host's lib directories and finds x86 libraries for your arm build.

You have to trick pkg-config into not searching your operating system for libraries, but some other directory where you've installed arm libraries.

1 Like

I figured out that i have to set more environment variables as described here. But im not sure what the difference between those vars (PKG_CONFIG_PATH, PKG_CONFIG_LIBDIR and PKG_CONFIG_SYSROOT_DIR) is and how to set them.
When i understand it right there are arm libraries in the /usr/arm-linux-gnueabihf/lib/ folder on my system.

This whole cross compiling topic is fairly new to me so i would appriciate any further help :slight_smile:

1 Like

I figured out that having pkg-build as only dependency just works fine.

And second i realized its just the alsa crate which causes the issues (not the entire midir crate).

I made a build script:

#!/bin/sh

export PKG_CONFIG_PATH=/usr/arm-linux-gnueabihf/lib
export PKG_CONFIG_ALLOW_CROSS=1

cargo build --target=armv7-unknown-linux-gnueabihf

But unfortunately this still dont help and i have no clue how to set those variables... Any help would be really appreciated!!

ps. what is a SYSROOT in all of this and where can i find it??