Created
April 24, 2024 16:14
-
-
Save lijiext/3e28f9b91446174fa2d81afa1f2237a3 to your computer and use it in GitHub Desktop.
aarch64 cross compile example on x86 ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
## SYSROOT was generated by | |
# sudo apt-get install qemu-user qemu-user-static debootstrap schroot | |
# sudo debootstrap --arch=arm64 focal /srv/chroot/arm64 http://ports.ubuntu.com/ | |
## | |
SYSROOT=/srv/chroot/arm64 | |
# module file for crossbuild complier | |
# /opt/admin/module/files/crossbuild/crossbuild/7.5.0: | |
# prepend-path PATH /opt/software/crossbuild/crossbuild/7.5.0/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin | |
# prepend-path LD_LIBRARY_PATH /opt/software/crossbuild/crossbuild/7.5.0/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/lib | |
# prepend-path CPATH /opt/software/crossbuild/crossbuild/7.5.0/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/include | |
# prepend-path MANPATH /opt/software/crossbuild/crossbuild/7.5.0/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/share | |
module load crossbuild/7.5.0 | |
CC=aarch64-linux-gnu-gcc | |
CXX=aarch64-linux-gnu-c++ | |
LD=aarch64-linux-gnu-ld | |
AR=aarch64-linux-gnu-ar | |
AS=aarch64-linux-gnu-as | |
NM=aarch64-linux-gnu-gcc-nm | |
STRIP=aarch64-linux-gnu-strip | |
RANLIB=aarch64-linux-gnu-ranlib | |
OBJDUMP=aarch64-linux-gnu-objdump | |
# this is inside of source code build dir, you may need to first | |
# tar -xvf <src.tar.gz> | |
# cd src | |
# mkdir build && cd build | |
# and then add this file to build.sh then excute it | |
../configure \ | |
--build=x86_64-linux-gnu \ | |
--host=aarch64-linux-gnu \ | |
--target=aarch64-linux-gnu \ | |
--cache-file=aarch64-linux-gnu.cache \ | |
--with-sysroot=${SYSROOT} \ | |
--prefix=`pwd`/dist | |
make -j $(nproc) | |
make install | |
# finally you will see the compile result in ./dist dir, and then you can install to the target machine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment