gtk-rs-core
gtk-rs-core copied to clipboard
[HELP] cross-compile gtk application to ARM raspberry
Hello, let me know if this is the right repository to ask.
I'm trying to cross-compile a simple rust GTK application on an Ubuntu 20.04 LTS from amd64 to ARM architecture for a raspberry2 (arm v6).
I first tried to cross-compile following some tutorials, but I encountered an issue about pkg-config
which I'm not able to solve and I can't find any resources about :/
I've already set the gcc arm linker for that target in ~/.cargo/config
.
When I run cargo build --target arm-unknown-linux-gnueabihf
i get:
The following warnings were emitted during compilation:
warning: pkg-config has not been configured to support cross-compilation.
error: failed to run custom build command for `gio-sys v0.16.0 (https://github.com/gtk-rs/gtk-rs-core.git#e6104a2d)`
Caused by:
process didn't exit successfully: `/home/massimo/Documenti/Programmi/gtk-test/target/debug/build/gio-sys-5f3d520153a7586a/build-script-build` (exit status: 1)
--- stdout
cargo:rerun-if-env-changed=GIO_2.0_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
cargo:warning=pkg-config has not been configured to support cross-compilation.
Install a sysroot for the target platform and configure it via
PKG_CONFIG_SYSROOT_DIR and PKG_CONFIG_PATH, or install a
cross-compiling wrapper for pkg-config and set it via
PKG_CONFIG environment variable.
warning: build failed, waiting for other jobs to finish...
error: build failed
I hope to contribute in writing some step by step guide if i manage to solve this cross-compile stuff, so maybe it can be added to the docs for everyone to use.
Thank you anyway
The error tells you what do do :) You need to configure pkg-config correctly for your ARM sysroot.
Thanks, I guess the issue was on my side, not knowing enough about what sysroots are and not finding enough information :/
After few more hours of research I managed to complete the compilation, I'll test the binary hoping it works.
If it works, what's the best place I could contribute to by adding some tutorial?
I think the best place would be the gtk4 book. Also: it would be very appreciated. :)
Seems the problem wasn't so easy as it seemed >.<
I made a folder with all the libraries from my raspberry 2 to use as a sysroot, then set in ~.cargo/config
[target.arm-unknown-linux-gnueabihf]
linker = "arm-linux-gnueabihf-gcc"
rustflags = ["-C", "link-args=--sysroot=/home/massimo/sysroot_pi"]
I also added an environment variable for pkgconfig
export PKG_CONFIG_SYSROOT_DIR="/home/massimo/sysroot_pi"
Everything seems to compile, but it generates a Segmentation fault when run on my raspberry pi 2.
It seems that gcc
doesn't link and create correct binaries for armv6 https://stackoverflow.com/a/65186762.
Running arm-linux-gnueabihf-readelf -A ./gtk-test
gives me a Tag_CPU_arch: v7
, so I'm kind of stuck.
This project recompiles the whole gcc from scratch in a container to solve it, maybe there's an easier solution?
In any case, I'll test if the overall process at least works for newer raspberry with target.armv7-unknown-linux-gnueabihf
triplet
You'll have to get and configure a toolchain for the correct target platform, yes.
Let us close this, if you think such information could be useful as part of the gtk4-rs book then please either open a detailed issue there or send a PR :)