I tried to cross compile "hello world" to raspberry pi zero on Ubuntu 20.04 .... Please help
You will need to install and use an arm linker.
I don't know about ubuntu but on manjaro I need to install
arm-linux-gnueabihf-gcc package to to cross compile to my
armv7-unknown-linux-gnueabihf target. See what's the equivalent on ubuntu
also check out cross, the idea is it uses preconfigured docker images to compile.
I don't know why and how .... but after reinstalling rustup and target (arm-unknown-linux-gnueabihf) ..... it's working ....
I used https://disconnected.systems/blog/rust-powered-rover/#cross-compile-hello-world
Well all those are needed if you have anything that has any dependencies on
C libraries (I can think of many, like openssl, sqlite etc). So normally I wouldn't expect a simple
hellow world to need a linker. Not sure why yours asked for one in the first place. nevertheless you might need one later.
Rust is incapable of cross-compiling executables and dynamic libraries by itself. Rust only knows how to cross-compile object files and maybe static libraries if you're lucky.
To get from cross-compiled object files to cross-compiled executable you need a cross-linker, which is not included in Rust distribution.
By default Rust uses your host operating system's linker, and ends up telling x86 linker to link ARM code, which won't work. You need to install ARM linker and tell Rust/Cargo to use the ARM linker instead.
On top of that you will find that sys crates (C dependencies) need a C compiler and/or pkg-config, but again you have x86 C compiler and x86 pkg-config with x86 libraries on your system, so none of this will work. You will also have to install ARM C compiler, and ARM system libraries and configure pkg-config to use the ARM libraries.
Overall, it's a lot of faff. See projects/guides that help with all of that setup:
Is there any chance of the situation with cross compiling getting better anytime soon? This is one area where I think rust fairly falls flat, and I just try not to touch anything that has sys in it's name with even a 10 foot pole when trying to cross compile to my pi.
FWIW I had to add
CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER=/usr/bin/arm-linux-gnueabihf-gcc before the cargo invocation to make the arm build work.
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.