Cross Toolchain Setup

Download And Install Toolchain Archive

  • Create a directory, say, ~/toolchains (you might well choose a different name). We will use that directory as a well-known place to put our toolchains in. (Toolchains tend to be updated a lot, and keeping different versions together in one directory helps organizing our work.)

  • Download the toolchain archive (a whopping 70MB)

  • Unpack the archive into ~/toolchains, as follows

    • Change into toolchain install directory

    $ cd ~/toolchains
    • Get an overview of the download, and see what’s in it

    $ ls -l ~/Downloads/armv8-rpi4-linux-gnueabihf-gcc-10.2-glibc-2.31.tar.xz
    -rw-r--r--. 1 jfasch jfasch 73018472 May 12 08:16 Downloads/armv8-rpi4-linux-gnueabihf-gcc-10.2-glibc-2.31.tar.xz
    $ tar -t -f ~/Downloads/armv8-rpi4-linux-gnueabihf-gcc-10.2-glibc-2.31.tar.xz | head
    • If you are fine, unpack it. This will create a directory ~/toolchains/armv8-rpi4-linux-gnueabihf - our toolchain base directory.

    $ tar -x -f ~/Downloads/armv8-rpi4-linux-gnueabihf-gcc-10.2-glibc-2.31.tar.xz
    $ ls -l ~/toolchains/
    total 0
    dr-xr-xr-x. 1 jfasch jfasch 128 Apr 17 12:01 armv8-rpi4-linux-gnueabihf

Establish CMake Toolchain File

  • Download the toolchain file into ~/toolchains

  • The toolchain file describes toolchain parameters for cross builds that you will perform using CMake, eventually. Modify the downloaded file to reflect your situation, by changing the following line:

    set(TOOLCHAIN_BASE_DIR /home/jfasch/toolchains/armv8-rpi4-linux-gnueabihf)

Test Run

  • You already have a CMake project that you maintain. Lets assume this is ~/project-source (a Git clone maybe).

  • Create another build directory - this time for a Raspi cross build:

    $ mkdir ~/project-build-raspi

    … and change into it:

    $ cd ~/project-build-raspi
  • Create the cross build instructions

    $ pwd
    $ cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/toolchains/armv8-rpi4-linux-gnueabihf.cmake ~/project-source
    ... roedel ...
  • Build it

    $ pwd
    $ make
    ... roedel roedel...