# Cross-compiler

## About this Install Guide

|                  |                 |
|------------------|-----------------|
| Reading time:    | 10 min          |
| Last updated:    | 10 Nov 2026     |
| Author:          | Jason Andrews, Arm [GitHub](https://github.com/jasonrandrews) [LinkedIn](https://linkedin.com/in/jason-andrews-7b05a8) |
| Official docs:   | [View](https://gcc.gnu.org/onlinedocs/) |

This guide shows you how to install and use the tool with the most common configuration. For advanced options and complete reference information, see the official documentation. Some install guides also include optional next steps to help you explore related workflows or integrations.

Install GCC cross-compilers on an x86-64 or Arm Linux host running Ubuntu or Debian to build applications for Arm Linux.

> **Note**  
> For bare-metal software or software that uses a real-time operating system (RTOS), use the [Arm GNU Toolchain](https://learn.arm.com/install-guides/gcc/arm-gnu) instead. It supports firmware development for Cortex-M, Cortex-R, and Cortex-A processors. Linux cross-compilers target applications that run on Arm Linux.

## Install cross-compilers

On Ubuntu or Debian, install the C and C++ cross-compilers for 32-bit and 64-bit Arm Linux:

```bash
sudo apt update
sudo apt install gcc gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
    gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf -y
```

The `gcc` package installs the native C compiler and its assembler and linker dependencies, which are also needed when building 64-bit Arm applications on a 64-bit Arm host.

| Compiler                     | Target                              |
|------------------------------|-------------------------------------|
| `aarch64-linux-gnu-gcc`      | 64-bit Arm Linux applications (AArch64) |
| `arm-linux-gnueabihf-gcc`    | 32-bit Arm Linux applications (AArch32, hard float) |

The corresponding C++ compilers are `aarch64-linux-gnu-g++` and `arm-linux-gnueabihf-g++`.

## Verify the installation

Verify the 64-bit cross-compiler is installed:

```bash
aarch64-linux-gnu-gcc --version
```

The output is similar to:

``` 
__output__ aarch64-linux-gnu-gcc (Ubuntu 15.2.0-16ubuntu1) 15.2.0
__output__ Copyright (C) 2025 Free Software Foundation, Inc.
__output__ This is free software; see the source for copying conditions.  There is NO
__output__ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

Verify the 32-bit cross-compiler is installed:

```bash
arm-linux-gnueabihf-gcc --version
```

The output is similar to:

``` 
__output__ arm-linux-gnueabihf-gcc (Ubuntu 15.2.0-16ubuntu1) 15.2.0
__output__ Copyright (C) 2025 Free Software Foundation, Inc.
__output__ This is free software; see the source for copying conditions.  There is NO
__output__ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

## Cross-compile a program

Create a file named `hello.c`:

```c
#include <stdio.h>

int main()
{
    printf("Hello, Arm World!\n");
    return 0;
}
```

Cross-compile for 64-bit Arm Linux:

```bash
aarch64-linux-gnu-gcc hello.c -o hello-arm64
```

Cross-compile for 32-bit Arm Linux:

```bash
arm-linux-gnueabihf-gcc hello.c -o hello-arm32
```

## Test with QEMU (optional)

QEMU user-mode emulation lets you run the compiled Arm Linux applications on your host. You don’t need QEMU to cross-compile.

On Ubuntu or Debian, install QEMU:

```bash
sudo apt install qemu-user -y
```

The `-L` option points QEMU to the target’s runtime libraries.

Test the 64-bit binary with QEMU:

```bash
qemu-aarch64 -L /usr/aarch64-linux-gnu ./hello-arm64
```

The output is similar to:

``` 
__output__ Hello, Arm World!
```

Test the 32-bit binary with QEMU:

```bash
qemu-arm -L /usr/arm-linux-gnueabihf ./hello-arm32
```

The output is similar to:

``` 
__output__ Hello, Arm World!
```

You can now cross-compile C and C++ applications for Arm Linux from your Linux host.
