Compiling and running ARM programs on x86_64

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:

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


About mcturra2000

Computer programmer living in Scotland.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s