- Download the source code for the gcc compiler from the official website. You can download the latest version from here: https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
wget https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz
Extract the source code:
tar xf gcc-11.2.0.tar.xz
Change to the directory where the source code was extracted:
cd gcc-11.2.0
Configure the build:
./configure --target=aarch64-linux-gnu --prefix=/usr/local
Build and install the compiler:
make -j4 && sudo make install This will build and install the aarch64-linux-gnu-gcc compiler into the /usr/local/bin directory.
Verify that aarch64-linux-gnu-gcc is installed:
aarch64-linux-gnu-gcc --version This should display the version of aarch64-linux-gnu-gcc that is installed on your system.
I suggest you try to build the toolchain from sources. It's easy with an open source tool called crosstool-ng. This method requires more time, but allows configuration of the toolchain and usually works well even if you use some old or uncommon system.
In order to install ct-ng, follow the instructions here:
https://crosstool-ng.github.io/docs/install/
The tool has a sample called aarch64-unknown-linux-gnu and it looks like the toolchain you need (to list all samples use ct-ng list-samples).
In order to initialize the configuration run:
ct-ng aarch64-unknown-linux-gnu
Then you can ct-ng nconfig to select specific options that you want to change. For example, you may want to change the version of GCC. You mentioned 7. So, select C compiler then Version of gcc and pick the one that you want. There should be several versions available.
When you're done selecting the options, run:
ct-ng build
In order to modify more things, for example the place where the toolchain shall be stored, you can use the docs: https://crosstool-ng.github.io/docs/configuration/
You can just try using them by downloading the .deb files for those packages from the Ubuntu site and installing them manually via dpkg:
Download the packages:
wget http://security.ubuntu.com/ubuntu/pool/main/g/gcc-7-cross/gcc-7-aarch64-linux-gnu-base_7.5.0-3ubuntu1~18.04cross1_amd64.deb
wget http://security.ubuntu.com/ubuntu/pool/main/g/gcc-7-cross/g++-7-aarch64-linux-gnu_7.5.0-3ubuntu1~18.04cross1_amd64.deb
Install them with dependencies via gdebi:
First, install `gdebi if you don't have it:
sudo apt install gdebi-core
Then, you can install both packages with their dependencies using gdebi:
sudo gdebi -i gcc-7-aarch64-linux-gnu-base_7.5.0-3ubuntu1~18.04cross1_amd64.deb
sudo gdebi -i g++-7-aarch64-linux-gnu_7.5.0-3ubuntu1~18.04cross1_amd64.deb
Just because it's not in the default apt repositories for 16.04, doesn't mean you can't go and get the packages yourself (be aware that they may not run or install properly on your older system though).
As of Ubuntu 18.04 you can do:
sudo apt-get install gcc-aarch64-linux-gnu
aarch64-linux-gnu-gcc -mcpu=cortex-a53 hello_world.c
The package gcc-aarch64-linux-gnu is at version 4:7.3.0-3ubuntu2
However, for Raspberry Pi, you should just download the official binaries from https://github.com/raspberrypi/tools which is the more reliable way to do it as explained at: https://raspberrypi.stackexchange.com/questions/64273/installing-raspberry-pi-cross-compiler/83215#83215
Finally, for bare metal, I was not able to find the analogue of arm-none-eabi-gcc, I wonder why: https://github.com/cirosantilli/cirosantilli.github.io/issues/68
You can try my Latest Pre-Built Open-Sourced GCC Toolchains for Raspberry Pi from this Github Project:
This Project Summary: This project contains the UpToDate set of Precompiled/Pre-Built Raspberry pi GCC Cross & Native Compilers Binaries, saving your tons of time(No compiling or Error Handling needed whatsoever). Just Extract, Link & Enjoy complete GCC(Raspberry Pi) functionality in your Machine. You can use its native compilers for Raspberry Pi(Can be used along with old & slow 6.3.0 GCC), Or use the Cross-Compiler in any Linux Machine(Tested on Latest Ubuntu/bionic x64) to compile programs for your Raspberry Pi. All these compilers binaries are Raspberry Pi hardware optimized for enhanced overall performance.
The Supported GCC Versions are:
- GCC 6.3.0
- GCC 7.4.0
- GCC 8.2.0
- GCC 8.3.0
Supported Environments:
- Cross-Compiler: All Linux Distros (x32/x64) are currently supported.
- Native-Compiler: All Raspberry Pi version/model with Raspbian OS is supported. Other OS may/may-not work.
Hope that helps! :)