Install gcc-arm-linux-gnueabi and binutils-arm-linux-gnueabi packages, and then just use arm-linux-gnueabi-gcc instead of gcc for compilation.

You need to be careful on what flavour of linux and binutils you have on your target system. The newest stuff is hardfloat, in this case you would do:

sudo apt-get install gcc-arm-linux-gnueabihf

This brings in the complete cross-compile environment, including binutils.

For using this GCC in the build process write:

CC=arm-linux-gnueabihf-gcc make
Answer from Maratyszcza on askubuntu.com
🌐
Jensd's I/O buffer
jensd.be › 1126 › linux › cross-compiling-for-arm-or-aarch64-on-debian-or-ubuntu
Cross compiling for arm or aarch64 on Debian or Ubuntu | Jensd's I/O buffer
January 26, 2021 - What is the solution to compile amd64, x86, arm, and aarch64 from on Ubuntu installation? ... Thank for the hint to install gcc-multilib. Installing it helped to compile https://github.com/debmint/osk-disasm ... How can I cross compile xen and xen tools for arm64 in ubuntu 20.04?
Top answer
1 of 4
74

Install gcc-arm-linux-gnueabi and binutils-arm-linux-gnueabi packages, and then just use arm-linux-gnueabi-gcc instead of gcc for compilation.

You need to be careful on what flavour of linux and binutils you have on your target system. The newest stuff is hardfloat, in this case you would do:

sudo apt-get install gcc-arm-linux-gnueabihf

This brings in the complete cross-compile environment, including binutils.

For using this GCC in the build process write:

CC=arm-linux-gnueabihf-gcc make
2 of 4
23

64-bit ARM

For 64-bit ARM, the toolchain prefix is aarch64 and usage is:

sudo apt install gcc-aarch64-linux-gnu
aarch64-linux-gnu-gcc -o main.out main.c

You can try it out on this C hello world with QEMU:

main.c

#include <stdio.h>

int main(void) {
    puts("hello");
}

and then:

sudo apt install qemu-user
qemu-aarch64 main.out

will output:

hello

Then a few fun things you can do to quickly see that ARM is actually running under the hood:

  • GDB step debug it: https://stackoverflow.com/questions/20590155/how-to-single-step-arm-assembly-in-gdb-on-qemu/51310791#51310791
  • log the executed ARM instructions with: qemu-aarch64 -d in_asm,out_asm main.out https://stackoverflow.com/questions/13005303/how-does-native-android-code-written-for-arm-run-on-x86/44505097#44505097

Tested in Ubuntu 19.10.

For reliability in serious applications, the disk image provider must also provide a compatible cross compiler

Although you can install a cross compiler with apt conveniently, I must warn you that this is not necessarily reliable unless explicitly supported by the image provider.

If you pick the cross compiler wrongly, the following may happen:

  • the dynamic linker is at the wrong path: https://stackoverflow.com/questions/31929092/trying-to-run-a-cross-compiled-executable-on-target-device-fails-with-no-such-f/49993116#49993116
  • binary incompatibility with the glibc and any other libraries you link against: https://stackoverflow.com/questions/11107263/how-compatible-are-different-versions-of-glibc

Raspberry PI cross compilation

For RPI in particular, the provided cross compilers are available at: https://github.com/raspberrypi/tools and can be used as explained at: https://raspberrypi.stackexchange.com/questions/64273/installing-raspberry-pi-cross-compiler/83215#83215

git clone https://github.com/raspberrypi/tools
export PATH="$(pwd)/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:${PATH}"
printf '#include <stdio.h>\nint main() { puts("hello world"); }\n' > hello_world.c
printf '#include <iostream>\nint main() { std::cout << "hello world" << std::endl; }\n' > hello_world.cpp
arm-linux-gnueabihf-gcc -std=c99 -o hello_world_c hello_world.c
arm-linux-gnueabihf-g++ -std=c++11 -o hello_world_cpp hello_world.cpp

Ubuntu cross compilation

If you want to cross compile for Ubuntu arm64, I have never been able to find a clear reference on which cross compilers support which distro version: What are the officially supported cross compilers for Ubuntu server alternative architectures like ARM?

Buildroot

My favorite alternative is to build your own image with Buildroot: https://stackoverflow.com/questions/47557262/how-to-download-the-torvalds-linux-kernel-master-recompile-it-and-boot-it-wi/49349237#49349237

This builds everything from source, including the toolchain and the image, and ensures that everything is compatible.

Discussions

Using cross-compilation for ARM64 in the Ubuntu 24.04 x86 environment
I would like to ask if my setup is correct. Why does the file not change to ARM64 after running cmake --install . ? sudo apt-get install gcc-aarch64-linux-gn... More on forum.qt.io
🌐 forum.qt.io
4
0
March 10, 2025
Cross compile for aarch64 on Ubuntu
I’ve got the tool chain file fairly well figured out. The problem I run into is that the sysroot is at /usr/aarch64-linux-gnu, while the arm64 libs and includes are in /usr/lib/aarch64-linux-gnu and /usr/include/aarch64-linux-gnu, where CMake’s find_package doesn’t find them. More on discourse.cmake.org
🌐 discourse.cmake.org
1
1
November 12, 2020
gcc - Cross-compiling PTPD2 for a 64-bit ARM A-53 under Ubuntu for x64 - Stack Overflow
I am attempting to cross-compile the PTPD project for 64-bit ARM (https://github.com/ptpd/ptpd). I have installed the aarch64 compilers and I can see the 64-bit ARM gcc compiler under /usr/bin/aarc... More on stackoverflow.com
🌐 stackoverflow.com
Does anyone here cross compile for arm64 musl? do you get frequent issues doing it?
I tried Gentoo, T2SDE and Void for this about a year ago and had issues on all 3. Can't say I put a great deal of effort in but after a few failures of each I shelfed the idea for while. Alpine seemed the most robust as they only really target musl. More on reddit.com
🌐 r/Gentoo
9
5
July 2, 2023
🌐
Google
android.googlesource.com › platform › external › armnn › + › refs › heads › upstream-master › BuildGuideCrossCompilation.md
How to Cross-Compile Arm NN on x86_64 for arm64
These are the step by step instructions on Cross-Compiling Arm NN under an x86_64 system to target an Arm64 Ubuntu Linux system. This build flow has been tested with Ubuntu 18.04 and 20.04 and it depends on the same version of Ubuntu or Debian being installed on both the build host and target ...
🌐
Qt Forum
forum.qt.io › home › qt development › installation and deployment › using cross-compilation for arm64 in the ubuntu 24.04 x86 environment
Using cross-compilation for ARM64 in the Ubuntu 24.04 x86 environment | Qt Forum
March 10, 2025 - sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu $ which aarch64-linux-gnu-gcc /usr/bin/aarch64-linux-gnu-gcc $ aarch64-linux-gnu-gcc --version aarch64-linux-gnu-gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0 Copyright (C) 2023 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. After verifying the cross-compilation tool, enter the Qt/6.8.2/ directory, create a folder, and start compiling. cd ./Qt/6.8.2/ mkdir arm64 mkdir build && cd build ../Src/configure -prefix /home/ptc/Qt/6.8.2/arm64 -platform linux-g++ -device linux-aarch64-gnu-g++ -device-option CROSS_COMPILE=aarch64-linux-gnu- -no-opengl -make libs
🌐
Arm Learning
learn.arm.com › install-guides › gcc › cross
Cross-compiler | Arm Learning Paths
Use the apt command to install the cross-compilers for 32-bit and 64-bit Arm Linux targets. sudo apt update sudo apt install gcc-arm-linux-gnueabihf -y sudo apt install gcc-aarch64-linux-gnu -y · The GCC version installed is tied to your Ubuntu ...
🌐
Ask Ubuntu
askubuntu.com › questions › 1410508 › cross-compiling-for-arm64-on-amd64-architecture
64 bit - Cross compiling for arm64 on amd64 architecture - Ask Ubuntu
May 25, 2022 - I don't think you should be installing packages like build-essential:arm64 at all - you should be using the native (i.e. amd64) cross compiler toolchain packages like gcc-aarch64-linux-gnu. See for example this introduction Cross compiling for arm or aarch64 on Debian or Ubuntu
🌐
Ask Ubuntu
askubuntu.com › questions › 1378154 › why-is-there-no-cross-compiler-in-arm64-version-of-ubuntu
package management - Why is there no cross-compiler in Arm64 version of Ubuntu? - Ask Ubuntu
The toolchain comes with the Clang C/C++/Obj-C compiler, and a functioning linker. ... One can enable "Multiarch" and run cross compiler built for x86_64 on arm64 through user-space QEMU program.
Find elsewhere
🌐
DEV Community
dev.to › offlinemark › how-to-set-up-an-arm64-playground-on-ubuntu-18-04-27i6
How to set up an ARM64 playground on Ubuntu 18.04 - DEV Community
June 25, 2020 - Here's how to compile it. $ aarch64-linux-gnu-g++-8 -o arm64main arm64main.cpp -static $ file arm64main arm64main: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, for GNU/Linux 3.7.0, BuildID[sha1]=7b1bbf64436de3f0e268d1d8ab93d2123d4dcaef, not stripped · Note the -static flag. We need this because the cross compiler by default generates dynamic binaries that rely on an ARM64 version of the dynamic linker, which we don't have.
🌐
YouTube
youtube.com › watch
Cross compiling for arm or aarch64 on Debian or Ubuntu - YouTube
In this video I'll explain how to do cross compiling for arm or aarch64 on Debian or Ubuntu. To make the resulting binaries portable, I'll also cover static ...
Published   January 30, 2021
🌐
OpenCV
docs.opencv.org › 4.x › d3 › dd9 › tutorial_crosscompile_with_multiarch.html
OpenCV: MultiArch cross-compilation with Ubuntu/Debian
December 2, 2023 - Execute sudo dpkg --add-architecture arm64 and/or sudo dpkg --add-architecture armhf. ... And sudo dpkg --print-foreign-architectures shows what foreign architectures are supported. ... With MultiArch, several shared libraries and pkg-config information for each architectures are stored into ...
🌐
Kodi Forum
forum.kodi.tv › showthread.php
Cross compiling to aarch64
January 10, 2023 - I can get my system to find these libraries on the compile device (x86_64) by doing this: sudo dpkg --add-architecture arm64 sudo touch /etc/apt/sources.list.d/arm-cross-compile-sources.list deb [arch=arm64] http://ports.ubuntu.com/ kinetic main restricted deb [arch=arm64] http://ports.ubuntu.com/ ...
🌐
Earthly
earthly.dev › blog › cmake-gcc-cross-compile
Using CMake and GCC to Cross-Compile Binaries - Earthly Blog
July 19, 2023 - Use the following command to install ... Ubuntu: sudo apt-get install gcc-aarch64-linux-gnu sudo apt-get install g++-aarch64-linux-gnu · Or use this command if you’re using RHEL or Fedora: sudo dnf install epel-release sudo dnf install gcc-aarch64-linux-gnu sudo dnf install gcc-c++-aarch64-linux-gnu · Before using CMake to cross-compile your program, you need to obtain the prebuilt root file system for the ARM64 target system...
🌐
DPDK
doc.dpdk.org › guides-19.11 › linux_gsg › cross_build_dpdk_for_arm64.html
4. Cross compile DPDK for ARM64 — Data Plane Development Kit 19.11.14 documentation
To install it in Ubuntu: ... To configure a build, choose one of the target configurations, like arm64-dpaa-linux-gcc and arm64-thunderx-linux-gcc. ... To cross-compile, including the kernel modules, the kernel source tree needs to be specified by setting RTE_KERNELDIR:
🌐
GitHub
github.com › uablrek › cross-compile
GitHub - uablrek/cross-compile: Howto cross-compile on Linux for arm64 (aarch64) · GitHub
This repo describes how to cross compile to the ARM64 architecture (aarch64), for example to RPi 4 and Radxa Rock 4se SoC boards. I rarely use official distributions, so native build is not an option, besides it's unbearably slow. Development and contributions are described below. I use Ubuntu ...
Author   uablrek
🌐
Linux Foundation
events17.linuxfoundation.org › sites › events › files › slides › Shuah_Khan_cross_compile_linux.pdf pdf
Cross-compiling Linux Kernels on x86_64
●Ubuntu arm64 packages (13.04 or later) – use arm64 · repo for older Ubuntu releases. – gcc-4.7-aarch64-linux-gnu · ●Ubuntu keeps adding support for compilers. Search · Ubuntu repository for packages. Cross-compiler packages · ●Embedded Debian Project is a good resource for alpha, mips, mipsel, powerpc, sh, and sparc cross-compilers.
🌐
DPDK
doc.dpdk.org › guides-21.02 › linux_gsg › cross_build_dpdk_for_arm64.html
4. Cross compiling DPDK for ARM64 — Data Plane Development Kit 21.02.0 documentation
Assuming the file with augmented c_args and c_link_args is named arm64_armv8_linux_clang, use the following command to cross-compile DPDK for the target machine: meson aarch64-build-clang --cross-file config/arm/arm64_armv8_linux_clang ninja -C aarch64-build-clang · On most popular Linux ...
🌐
Stack Overflow
stackoverflow.com › questions › 70020325 › cross-compiling-ptpd2-for-a-64-bit-arm-a-53-under-ubuntu-for-x64
gcc - Cross-compiling PTPD2 for a 64-bit ARM A-53 under Ubuntu for x64 - Stack Overflow
I am attempting to cross-compile the PTPD project for 64-bit ARM (https://github.com/ptpd/ptpd). I have installed the aarch64 compilers and I can see the 64-bit ARM gcc compiler under /usr/bin/aarc...