Arm-Linux Cross compile error

Hello.
I have a problem with cross compile for arm-linux (Beaglebone black).

Build command:
PKG_CONFIG_ALLOW_CROSS=1 cargo build --color=always --target=armv7-unknown-linux-gnueabihf

Error:
= note: /lib/x86_64-linux-gnu/libudev.so*: file not recognized: Nierozpoznawalny format pliku
collect2: error: ld returned 1 exit status
error: aborting due to previous error

Log: https://pastebin.com/LaTyEM4x

How to set cross compiler?
How fix it?

PKG_CONFIG_ALLOW_CROSS=1 breaks things, because pkg-config does not support cross-compilation. pkg-config is a simple tool that doesn't understand that concept at all, which is why it gets disabled to avoid causing problems.

It's theoretically possible to make pkg-config not break cross-compilation, but it takes a significant amount of work. It's not a matter of setting a variable, but you need to actually install arm-compatible libraries, get arm-compatible .pc files for them, and then override pkg-config directories (setting so-called sysroot) to make it see only the arm-specific versions.

Try to build everything static/vendored instead.

I did solved this with docker.

Dockerfile:

FROM rustembedded/cross:arm-unknown-linux-gnueabihf

RUN apt-get update && apt-get install -y --no-install-recommends apt-utils

RUN dpkg --add-architecture armhf && \
    apt-get update && \
    apt-get install --assume-yes libpthread-stubs0-dev:armhf && \
    apt-get install --assume-yes libudev-dev:armhf && \
    apt-get install --assume-yes libudev1:armhf && \
    apt-get install --assume-yes pkg-config

On docker container :

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add arm-unknown-linux-gnueabihf
root@aa6d9e933b0f:/home# ls /usr/lib/arm-linux-gnueabihf/pkgconfig
libudev.pc  pthread-stubs.pc

build.sh:

#!/bin/sh

SYSROOT=

export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export PKG_CONFIG_LIBDIR=${SYSROOT}/usr/lib/pkgconfig:${SYSROOT}/usr/share/pkgconfig
export PKG_CONFIG_SYSROOT_DIR=${SYSROOT}
export PKG_CONFIG_ALLOW_CROSS=1

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

This crate has instructions how to build it: https://github.com/dcuddeback/libudev-sys#cross-compiling

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.