自分用メモ ARM64クロスコンパイルとx86_64での実行
参考サイト
環境はx86_64, Ubuntu 18.04.2 LTS。
まず、qemuとg++-aarch64-linux-gnuを以下のようにインストール。
$ sudo apt-get install qemu $ sudo apt-get install g++-aarch64-linux-gnu
helloworld.c
#include <stdio.h> int main() { printf("hello world\n"); return 0; }
クロスコンパイル
$ aarch64-linux-gnu-gcc -o helloworld_arm64 helloworld.c
fileコマンドを実行してみる
$ file helloworld_arm64 helloworld_arm64: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-, for GNU/Linux 3.7.0, BuildID[sha1]=0b7252ec780aca58b8d0d95f117438281433d569, not stripped
実行
$ qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./helloworld_arm64 hello world
以下のようにスタティックリンクすると、qemu-aarch64を使わなくても実行できるのはなぜ? 勝手に裏でqemu-aarch64が実行される?
$ aarch64-linux-gnu-gcc -o helloworld_arm64_static -static helloworld.c $ ./helloworld_arm64_static hello world