Qemu AArch64 User-Space Emulation

Installing Qemu and Cross-Compiler

These can be installed manually (qemu, aarch64-linux-gnu) or by using a package manager:

sudo apt-get install -y qemu gcc-aarch64-linux-gnu

Running an Example

Given the following C program cross.c:

#include <stdio.h>
int main(void) {
    printf("cross compile me\n");
    return 0;
}

It can be cross-compiled with aarch64-linux-gnu-gcc cross.c -o cross and run on qemu with qemu-aarch64 cross. However, this produces an error: /lib/ld-linux-aarch64.so.1: No such file or directory.

Fixing the ld-linux-aarch64.so.1 Error

The problem generated by Qemu is there is no shared object file for aarch64:

/lib/ld-linux-aarch64.so.1: No such file or directory

And if there is, then this error will likely be encountered:

error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

One solution is to compile statically: aarch64-linux-gnu-gcc -static hello.c -o hello and then run qemu-aarch64 hello.

The other solution is to add the missing files, /lib/ld-linux-aarch64.so.1 and /lib64/libc.so.6.

Theses can be found on an AArch64 linux installation (i.e. a Raspberry Pi 3 with OpenSUSE). They are also available here:

Now the original cross-compiled program should work and produce the following output without any errors:

cross compile me