This post gives instructions on comping and running ARM 32-bit programs on an x86_64 using Ubuntu 19.10 and the GCC toolchain. The resulting binary also runs on a Raspberry Pi 2, and probably any Pi variant.
Install the cross-platform toolchain:
sudo apt install qemu-user qemu qemu-user-static sudo apt install gcc-arm-linux-gnueabi sudo apt install binutils-arm-linux-gnueabi
Additional dependencies given in this post may also be necessary.
Create the file hello.c
:
#include int main() { puts("Hello world"); return 0; }
Compile it:
arm-linux-gnueabi-gcc -static hello.c -o hello
You can check details about the executable by typing file hello
:
hello: ELF 32-bit LSB executable, ARM, EABI5 ...
Run it:
qemu-arm hello
That’s it. You can copy the exe to a Pi 2, and it should work fine.
You might also consider installing the following compiler: arm-linux-gnueabihf-gcc