Skip to content

Native Compiler: Installation Instructions

Abhishek Thakur edited this page Jun 19, 2019 · 67 revisions

Raspberry Pi Native Compiler Toolchain Installation Instruction 📑

Note::bulb: These instructions are exclusively for GCC Native Compiler version 9.1.0 but will work with all compiler versions available with this project.

 

A. Prerequisites:

  • Update your environment:

    sudo apt-get update && dist-upgrade
  • Install Important Packages(including default gcc):

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

 

B. Download Binary:

  • Visting download page on Browser: You can easily visit downloading page and find suitable cross-binaries for your Machine. Click Link given below:
  • Through Terminal: You can also download files directly from your terminal with wget as follows:
    wget 'https://sourceforge.net/projects/raspberry-pi-cross-compilers/files/Raspberry%20Pi%20GCC%20Native-Compiler%20Toolchains/GCC%209.1.0/Raspberry%20Pi%202%2C%203/native-gcc-9.1.0-pi_2-3.tar.gz'

 

C. Extracting and Linking Binary:

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

This repository now provides Free-Standing Native-Compiler Toolchains that gives a common setup for everyone, the same standardized headers with no hardcoded paths, therefore same solutions for everyone.

  • Extraction: Extract using tar terminal command as follows:

    tar xf <filename e.g native-gcc-9.1.0-pi_2-3.tar.gz>
  • Linking:

    • Setup paths as follows:
    PATH=/<extracted folder-name e.g native-pi-gcc-9.1.0-1>/bin:$PATH
    LD_LIBRARY_PATH=/<extracted folder-name e.g native-pi-gcc-9.1.0-1>/lib:$LD_LIBRARY_PATH

 

2. Permanent Installation:

  • Extraction: Extract using tar terminal command as follows:

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

    sudo mv <extracted folder-name e.g native-pi-gcc-9.1.0-1> /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 native-pi-gcc-9.1.0-1>/bin:$PATH' >> .profile  
       echo 'export LD_LIBRARY_PATH=/opt/<extracted folder-name e.g native-pi-gcc-9.1.0-1>/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 native-pi-gcc-9.1.0-1>/bin:$PATH' >> .bashrc
       echo 'export LD_LIBRARY_PATH=/opt/<extracted folder-name e.g native-pi-gcc-9.1.0-1>/lib:$LD_LIBRARY_PATH' >> .bashrc
       source .bashrc

 

E. Bonus:

  • Extra Step to use these binaries(temporarily) as your default native GCC Compiler(instead of default GCC 6.3.0) at the time of compilation: (For more info. refer #16, thanks @krcroft)

    export AR="gcc-ar-9.1.0"
    export CC="gcc-9.1.0"
    export CXX="g++-9.1.0"
    export CPP="cpp-9.1.0"
    export FC="gfortran-9.1.0"
    export RANLIB="gcc-ranlib-9.1.0"
    export LD="$CXX"
  • Further, To enable Link-time-optimization (LTO):

    GCCPATH="/opt/<extracted folder-name e.g native-pi-gcc-9.1.0-1>/libexec/gcc/arm-linux-gnueabihf/9.1.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.


Clone this wiki locally