Reading time: | 15 min |
Last updated: | 16 Dec 2024 |
Test status: |
Reading time: |
15 min |
Last updated: |
16 Dec 2024 |
Test status: |
This guide is intended to get you up and running with this tool quickly with the most common settings. For a thorough review of all options, refer to the official documentation.
GCC is available on all Linux distributions and can be installed using the package manager.
This covers gcc
and g++
for compiling C and C++ as a cross-compiler targeting the Arm architecture.
GCC is often used to cross-compile software for Arm microcontrollers and embedded devices which have firmware and other low-level software. The executables are arm-none-eabi-gcc
and arm-none-eabi-g++
.
GCC is also used to cross compile Linux applications. Applications can be compiled for 32-bit or 64-bit Linux systems.
The executables for 32-bit are arm-linux-gnueabihf-gcc
and arm-linux-gnueabihf-g++
.
The executables for 64-bit are aarch64-linux-gnu-gcc
and aarch64-linux-gnu-g++
.
Software can be compiled on an x86
or Arm
host machine.
The Linux package manager will download the required files so there are no special download instructions.
You can install a GCC cross compiler with Arm as a target architecture using Linux package managers.
Use the apt
command to install software packages on any Debian based Linux distribution.
sudo apt update
sudo apt install gcc-arm-none-eabi -y
sudo apt install gcc-arm-linux-gnueabihf -y
sudo apt install gcc-aarch64-linux-gnu -y
Fedora uses the dnf
package manager.
To install the most common development tools use the commands below.
If the machine has sudo
you can use it:
sudo dnf update -y
sudo dnf install arm-none-eabi-gcc-cs -y
sudo dnf install arm-none-eabi-newlib -y
sudo dnf install gcc-aarch64-linux-gnu -y
sudo dnf install gcc-arm-linux-gnu -y
If sudo
is not available become root and omit the sudo
from the above commands:
dnf update -y
dnf install arm-none-eabi-gcc-cs -y
dnf install arm-none-eabi-newlib -y
dnf install gcc-aarch64-linux-gnu -y
dnf install gcc-arm-linux-gnu -y
You can install a GCC cross compiler with Arm as a target architecture using Homebrew, a package manager for macOS (and Linux).
brew install arm-none-eabi-gcc
GCC is open source and freely available for use.
To confirm the installation is successful, enter:
arm-none-eabi-gcc --version
To compile an example program, create a text file named hello-world-embedded.c
with the contents below.
#include <stdio.h>
int main()
{
printf("Hello, Arm World!\n");
return 0;
}
To compile hello-world as a bare-metal application:
arm-none-eabi-gcc --specs=rdimon.specs hello-world-embedded.c -o hello-world.elf
To cross-compile hello-world as a 32-bit Linux application. On Fedora, only building kernels is currently supported. Support for cross-building user space programs is not currently provided as that would massively multiply the number of packages.
arm-linux-gnueabihf-gcc hello-world-embedded.c -o hello-world.elf
To cross-compile hello-world as a 64-bit Linux application. On Fedora, only building kernels is currently supported. Support for cross-building user space programs is not currently provided as that would massively multiply the number of packages.
aarch64-linux-gnu-gcc hello-world-embedded.c -o hello-world.elf
How would you rate the overall quality of this tool quick-install guide?
What is the primary reason for your feedback ?
Thank you. We're grateful for your feedback on how to improve this tool quick-install guide.