Cross Toolchain Setup¶
Download And Install Toolchain Archive¶
Create a directory, say,
~/x-tools
(the Crosstool-NG default name, 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 organize our work.)Download the toolchain archive (a whopping 70MB)
Unpack the archive into
~/x-tools
, as followsChange into toolchain install directory
$ mkdir ~/x-tools $ cd ~/x-tools
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 armv8-rpi4-linux-gnueabihf/ armv8-rpi4-linux-gnueabihf/armv8-rpi4-linux-gnueabihf/ armv8-rpi4-linux-gnueabihf/armv8-rpi4-linux-gnueabihf/sysroot/ armv8-rpi4-linux-gnueabihf/armv8-rpi4-linux-gnueabihf/sysroot/usr/ armv8-rpi4-linux-gnueabihf/armv8-rpi4-linux-gnueabihf/sysroot/usr/include/ armv8-rpi4-linux-gnueabihf/armv8-rpi4-linux-gnueabihf/sysroot/usr/include/asm-generic/ armv8-rpi4-linux-gnueabihf/armv8-rpi4-linux-gnueabihf/sysroot/usr/include/asm-generic/auxvec.h armv8-rpi4-linux-gnueabihf/armv8-rpi4-linux-gnueabihf/sysroot/usr/include/asm-generic/bitsperlong.h armv8-rpi4-linux-gnueabihf/armv8-rpi4-linux-gnueabihf/sysroot/usr/include/asm-generic/bpf_perf_event.h armv8-rpi4-linux-gnueabihf/armv8-rpi4-linux-gnueabihf/sysroot/usr/include/asm-generic/errno-base.h ...
If you are fine, unpack it. This will create a directory
~/x-tools/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 ~/x-tools/ 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~/x-tools
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/x-tools/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 /home/jfasch/project-build-raspi $ cmake -DCMAKE_TOOLCHAIN_FILE=$HOME/x-tools/armv8-rpi4-linux-gnueabihf.cmake ~/project-source ... roedel ...
Build it
$ pwd /home/jfasch/project-build-raspi $ make ... roedel roedel...