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
🌐
Arm Learning
learn.arm.com › install-guides › gcc › cross
Cross-compiler | Arm Learning Paths
This covers gcc and g++ for compiling C and C++ as a cross-compiler targeting the Arm Linux architecture.
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

c++ - How to compile a gcc compiler for arm on a X86 PC - Stack Overflow
i am using zedboard, I know that if I want to compile a program for an ARM device I need a special version of gcc that runs under x86 and compiles for ARM (cross compiling) ,i want to know is it po... More on stackoverflow.com
🌐 stackoverflow.com
gcc - Cross-Compiling for an embedded ARM-based Linux system - Stack Overflow
I try to compile some C code for an embedded (custom) ARM-based Linux system. I set up an Ubuntu VM with a cross-compiler named arm-linux-gnueabi-gcc-4.4 because it looked like what I needed. Now w... 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
Cross compiling for ARM based BeagleBone black - 'No rule to make target'
To cross-compile a module you need the headers for the kernel you are building for. They include the top level Makefiles that have the "module" target. In your case I would say that the KDIR variable should point to the headers directory, and the kernel Makefile will then use the "M" to locate the c-file you want to build. More on reddit.com
🌐 r/embedded
5
7
February 25, 2024
🌐
Reddit
reddit.com › r/c_programming › cross compiling in gcc?
r/C_Programming on Reddit: Cross compiling in GCC?
March 8, 2017 -

I have successfully compiled my program for a arm processor using GCC on Ubuntu PC, but I'm unable to figure out why my other solution didn't work. A few days ago I installed gcc-multilib, which automatically uninstalled the GCC cross compiler I already had installed (arm-linux-gnueabi-gcc), but when compiling using the option gcc -march=armv7-a

I get the error: error: bad value (armv7-a) for -march= switch

for each of my four sources files. Why would it not compile for the arm processor and what does this error even mean? I had to reinstall arm-linux-gnueabi-gcc, which uninstalled gcc-multilib, but it compiled like it did previously for cross compiling my program.

Top answer
1 of 6
4

It is a hard but doable task.

It depends on what ARM series you are compiling against. On many systems you find a Cortex-A (armv7-a or higher) or ARM11 (armv6) processor running a "mini Linux distribution", this is the case for many POS (Point of Sale) devices. In such a case your target can be one of the following:

  • arm-linux-gnueabi
  • arm-linux-gnueabihf

Where hf stands for hard-float, meaning that the CPU has a FPU (floating-point unit), all Cortex-A support this, but also depends on the underlying OS. It is also very important to know the version of the glibc on the embedded Linux, because if versions are not the same between compiler and OS, unexpected behavior may occur.

If you are compiling against an ARM processor without MMU (Memory Magament Unit) like the Cortex-R or Cortex-M series, and that by consequence do not support Linux (only microkernels like FreeRTOS) your target would be (also known as bare-metal):

  • arm-none-eabi

ARM now distributes the binaries of GCC:

https://developer.arm.com/tools-and-software/open-source-software/developer-tools/gnu-toolchain/gnu-a/downloads

Previously it was Linaro. Yet they keep GCC 7.x for arm-linu-gnueabi (soft-float) if you need it.

https://releases.linaro.org/components/toolchain/binaries/latest-7/

Linaro also used a build system known as ABE, I have not found much documentation on it, but they used it to configure and build the toolchains distributed by them.

If none of the above works for you, you can still build your own toolchain, for that task I suggest using crosstool-ng: https://crosstool-ng.github.io/

Works best under a Linux OS like Ubuntu (you can still try to use Cygwin to build it on Windows, but it may take more time). Note that you do not need to compile it in the machine you want to run it, meaning that you can compile on Ubuntu the GCC that will run on Windows which will produce programs that run on ARM processor, this is known as Canadian Cross.

2 of 6
2

I recommend getting a cross-compiler binary. On a Linux distribution it is often already packaged.

However, if you insist on building GCC from source (but beware of dependencies), read about Installing GCC and about Configuring GCC. You should build it outside of the source tree, and you want to pass some particular --target= option. I also recommend something like --program-suffix=_my

(I have no idea what --target is relevant for your particular configuration & board; you need to find out)

Notice that a target is not only a CPU, but also an OS....

🌐
Medium
ruvi-d.medium.com › a-master-guide-to-linux-cross-compiling-b894bf909386
A master guide to Linux cross compiling | by Ruvinda Dhambarage | Medium
January 18, 2026 - | Component | Type | Build | Host | Target | |-----------|-------------|--------|--------|--------| | GCC | Compiler | x86_64 | x86_64 | armv7 | | CMake | Build tool | x86_64 | x86_64 | N/A | | Awesome | Application | x86_64 | armv7 | N/A |
🌐
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 - At this point we’re ready to do the actual cross compile by running make: jensd@deb10:~/strace-5.10$ make aarch64-linux-gnu-gcc -E -P -DHAVE_CONFIG_H \ ... jensd@deb10:~/strace-5.10$ file strace strace: ELF 64-bit LSB executable, ARM aarch64, version 1 (GNU/Linux), statically linked, for GNU/Linux 3.7.0, BuildID[sha1]=db1ce4305df1dac73b81efe99847725d65ac9ab4, with debug_info, not stripped
🌐
OSDev Wiki
wiki.osdev.org › GCC_Cross-Compiler
GCC Cross-Compiler - OSDev Wiki
1 week ago - Instead you should build it yourself with arm-none-eabi being the $TARGET. The GNU Compiler Collection is an advanced piece of software with dependencies. You need the following in order to build GCC:
Find elsewhere
🌐
GitHub
github.com › narke › gcc-cross-compiler
GitHub - narke/gcc-cross-compiler: A script to cross-compile GCC toolchain for various target architectures. · GitHub
Cross-compiler toolchain build script Possible target platforms are: aarch64 ARM64 amd64 AMD64 (x86-64, x64) arm32 ARM armhf ARM hard float ia32 IA-32 (x86, i386) ia64 IA-64 (Itanium) mips32 MIPS little-endian 32b mips32eb MIPS big-endian 32b mips64 MIPS little-endian 64b ppc32 32-bit PowerPC ppc64 64-bit PowerPC sparc32 SPARC V8 sparc64 SPARC V9 lm32 LatticeMico32 The toolchain is installed into directory specified by the CROSS_PREFIX environment variable.
Starred by 61 users
Forked by 13 users
Languages   Python
🌐
Earthly
earthly.dev › blog › cmake-gcc-cross-compile
Using CMake and GCC to Cross-Compile Binaries - Earthly Blog
July 19, 2023 - This tutorial showed you the basics of cross-compiling a C++ program for ARM64 devices using CMake and GCC.
🌐
TutorialsPoint
tutorialspoint.com › article › compiling-native-gcc-for-arm-using-cross-compiler
Compiling native GCC for arm using cross-compiler
March 3, 2023 - By using a cross-compiler like Linaro, developers can generate optimized ARM executables from x86 development machines. This process involves installing the toolchain, configuring environment variables, and compiling GCC with appropriate target ...
🌐
Acmesystems
acmesystems.it › arm9_toolchain
Install the ARM cross compiler toolchain on your Linux PC
Install the GCC, G++ cross compilers and support programs by typing: sudo apt update sudo apt install libc6-armel-cross libc6-dev-armel-cross binutils-arm-linux-gnueabi libncurses5-dev build-essential bison flex libssl-dev bc
🌐
96Boards
96boards.org › documentation › guides › crosscompile › commandline.html
Cross Compile files on x86 Linux host for 96Boards ARM systems - 96Boards
If your 96Board is a 64bit SoC ... will use the 64bit toolchain. For ARM 32bit toolchain · $ sudo apt-get install gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf ·...
🌐
LinkedIn
linkedin.com › pulse › cross-compiling-gcc-toolchain-arm-cortex-m-processors-ijaz-ahmad
Cross-Compiling GCC Toolchain for ARM Cortex-M Processors
March 14, 2019 - Now that C-Libraries (newlib) is cross-compiled successfully; it's time to add its support to the earlier build gcc compiler to complete it. cd ~/toolchain/build/gcc-build ../../gcc-6.4.0/configure --target=arm-none-eabi --prefix=/home/linuxlite/arm-none-eabi --with-cpu=cortex-m4 \ --enable-languages=c,c++ --with-newlib --with-no-thumb-interwork --with-mode=thumb
🌐
Arm Developer
developer.arm.com › downloads › - › gnu-a
Downloads | GNU-A Downloads – Arm Developer
The toolchain includes the GNU Compiler (GCC) and is available free of charge directly for Windows and Linux operating systems. Follow the links on this page to download the correct version for your development environment. See the downloaded package Release Notes, which are linked from this page, for full installation instructions. ... We are pleased to announce the Arm release of the pre-built GNU cross-toolchain for the A-profile cores: GCC 10.3-2021.07.
🌐
Suchprogramming
suchprogramming.com › cross-compiling-c-code-for-arm
Such Programming - Cross Compiling C Code for ARM
December 15, 2017 - To build, I’ll use the arm-linux-gnueabi-gcc compiler instead of just gcc. I’ll verify it was indeed for an ARM machine with readelf. Next, to test it, I’ll scp it over to my OpenBMC system, ssh into it and give it a go! There it is! I’ve successfully cross compiled a simple program to run on an ARM machine.
🌐
Arm Learning
learn.arm.com › install-guides › gcc
GNU Compiler | Arm Learning Paths
Use this option to install GCC using the Linux package manager and build bare metal applications by cross compiling them for the Arm architecture from an x86 or Arm Linux host machine.
🌐
GitHub
github.com › abhiTronix › raspberry-pi-cross-compilers › wiki › 64-Bit-Cross-Compiler:-Installation-Instructions
64 Bit Cross Compiler: Installation Instructions
September 7, 2024 - This project now provides exclusive 64-bit ARM64 (aka AArch64) Raspberry Pi GCC Toolchains. These ARM64 Toolchains can be used on any Linux Distributions (32-bit/64-bit) for cross-compiling programs for any Raspberry Pi 64-Bit OS flavors with 64-bit kernel only (such as Raspberry Pi OS (64-bit)).
Author   abhiTronix
🌐
GitHub
github.com › apritzel › cross
GitHub - apritzel/cross: GCC Crosscompiler build scripts and instructions · GitHub
In opposite to native builds, --build ... native gcc tell configure the build machine's triplet. Please don't hardcode x86_64-linux-gnu in scripts ;-) ... Put your target's machine triplet and a trailing hyphen into the CROSS_COMPILE environment variable. ... Some packages (Linux, Xen, u-boot come to mind) expect a specifier for the target architecture in the ARCH environment variable. $ make ARCH=arm64 ...
Starred by 59 users
Forked by 19 users
Languages   Shell