Skip to content

64 Bit Cross Compiler: Installation Instructions

Abhishek Thakur edited this page Feb 5, 2020 · 38 revisions

Raspberry Pi Toolchains Logo

Raspberry Pi GCC 64-Bit Cross-Compiler Toolchains Setup Guide

This project now provides exclusive 64-bit ARM64 (aka AArch64) Raspberry Pi GCC Toolchains. These ARM64 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 Pi64 by @bamarni).

Supported Pi Models:

These toolchains can be used with any Raspberry Pi Models/Versions with ARMV8-A CPU Architecture that supports 64-Bit execution state. You can find complete all supported Pi's list here.

 


Important ⚠️

  • These instructions are exclusively for GCC version 9.2.0 but will work with any compiler version available with this project.

  • These instructions are Linux-machines specific only.


 

Table of content

 

 

A. Prerequisites

  • Update your environment:

    sudo apt update && sudo apt dist-upgrade
  • Install Important Packages:

    sudo apt-get install build-essential gawk gcc g++ gfortran git texinfo bison libncurses-dev

 

 

B. Download Binary

Compressed pre-compiled GCC Toolchain binaries can be easily be downloaded from the project's SourceForge Repository by clicking links given in the following table:

Toolchains Binaries Status GCC versions
Raspberry Pi GCC 64-Bit Cross-Compiler Toolchains Stable/Production 6.3.0, 8.3.0, 9.2.0

 

 

C. Extracting and Linking Binary

These Raspberry toolchains have the same standardized headers with no hardcoded paths, thereby can be directly used for immediate application OR can be installed permanently for on a daily basis usage.

C1. Temporary Installation: Use these binaries directly (Recommended)

  • Extraction: Extract using tar terminal command as follows:

    tar xf <filename e.g cross-gcc-9.2.0-pi_64.tar.gz>
  • Linking:

    PATH=/<extracted folder-name e.g cross-pi-gcc-9.2.0-64>/bin:$PATH
    LD_LIBRARY_PATH=/<extracted folder-name e.g cross-pi-gcc-9.2.0-64>/lib:$LD_LIBRARY_PATH

 

C2. Permanent Installation:

  • Extraction: Extract using tar terminal command as follows:

    tar xf <filename e.g cross-gcc-9.2.0-pi_64.tar.gz>
  • Configuring: Move extracted folder to any location (for e.g. /opt) by using following command:

    sudo mv <extracted folder-name e.g cross-pi-gcc-9.2.0-64> /opt
  • Linking: Properly link Path/Environment Variables permanently with either of the following given methods:

    • Appending variables to your .profile: (Recommended)

       echo 'export PATH=/opt/<extracted folder-name e.g cross-pi-gcc-9.2.0-64>/bin:$PATH' >> .profile  
       echo 'export LD_LIBRARY_PATH=/opt/<extracted folder-name e.g cross-pi-gcc-9.2.0-64>/lib:$LD_LIBRARY_PATH' >> .profile
       source .profile
    • Appending variables to your .bashrc: ⚠️ Some Linux users reported some trouble with configuring path variables at .profile that doesn't seem to work for them. If you encounter a similar problem, try setting/configure by adding paths to your .bashrc file instead of as follows:

       echo 'export PATH=/opt/<extracted folder-name e.g cross-pi-gcc-9.2.0-64>/bin:$PATH' >> .bashrc
       echo 'export LD_LIBRARY_PATH=/opt/<extracted folder-name e.g cross-pi-gcc-9.2.0-64>/lib:$LD_LIBRARY_PATH' >> .bashrc
       source .bashrc

 

 

D. Advanced Information

  • To enable Link-time-optimization (LTO):

    export AR="aarch64-linux-gnu-gcc-ar"
    export CC="aarch64-linux-gnu-gcc"
    export CXX="aarch64-linux-gnu-g++"
    export CPP="aarch64-linux-gnu-cpp"
    export FC="aarch64-linux-gnu-gfortran"
    export RANLIB="aarch64-linux-gnu-gcc-ranlib"
    export LD="$CXX"
    
    GCCPATH="/<extracted folder-name e.g cross-pi-gcc-9.2.0-1>/libexec/gcc/aarch64-linux-gnu/9.2.0"
    export ARFLAGS="--plugin $GCCPATH/liblto_plugin.so"
    export RANLIBFLAGS="--plugin $GCCPATH/liblto_plugin.so"

    NOTE: 💡 LTO also needs g++ to be the linker, and it can be enabled at compile-time by setting -flto=$(nproc) and -fno-fat-lto-objects flags in CFLAGS, CXXFLAGS, and LDFLAGS respectively.

  • Extra flag required while using custom SYSROOT Folder during build:

    While using a seperate custom SYSROOT Folder for your builds (for example in case of QT builds), kindly add -no-gcc-sysroot flag to your configure command to avoid undesired errors and failures.

  • Extra step to use Cross-Compiler Binaries with CMAKE:

    Enable CMAKES's implicit directory feature by injecting the following lines into toolchain file: (Refer Issue:#3)

    unset(CMAKE_C_IMPLICIT_INCLUDE_DIRECTORIES)
    unset(CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES)