Raspberry Pi 3 - Windows 7 64bit CrossCompiler Toolchain Setup


The Raspberry Pi runs a Linux distribution (Raspbian) with its own development toolchain. However, it is slow. In many cases it would be much faster to build your code locally on a host OS - Windows, OSX or another Linux distribution - then upload the binary files to the Pi device. In order to do this we need to build a local copy of the Raspberry Pi toolchain on the local host machine, so that the C/C++ source code can be built natively on Windows and the binary can be executed on both platforms.

This guide will demonstrate the steps needed to take a cross platform C/C++ toolchain from a remote Raspberry Pi 3 / Linux 4.11 / ARM v8 device and rebuild that toolchain locally so that it will also run on a host Windows 7 machine.

The end goal being that you will be able to compile your C/C++ code on Windows, then upload it and run it, on the remote Raspberry Pi 3 device itself.

We will be using CrossTool (http://crosstool-ng.github.io/) to configure the cross platform toolchain build.

We also need a native toolchain to build the cross platform toolchain. For this we will use Cygwin (https://www.cygwin.com/)

First some things to note:

Cygwin is slow. It will take several hours to complete the build of the RPI toolchain. It is recommended that you use a different package manager for a more optimized workflow. We use Cygwin here only as an example.

While this guide will use the C drive as an example, you will need considerable space to setup both cygwin and crosstool, so it is highly recommend that you pick your location carefully.

Finally, if you want to automate this entire workflow in a script please be aware that Cygwin setup.exe is known to have limitations when using it on the command line. See https://cygwin.com/install.html for details.


A. Cygwin Setup

  1. Run regedit.exe and set following key to zero(0):

            
    HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\kernel\obcaseinsensitive

  2. Download and run Cygwin 64bit setup.exe

  3. Set the Cygwin home and temp (for downloads) directories

  4. Select following Cygwin packages:

autoconf,

automake,

bison,

diffutils,

flex,

gawk,

gcc-g++,

git,

gperf,

help2man,

libncurses-devel,

make,

patch

python2-devel,

texinfo,

wget,

Xz,

nano

  1. Select “Select required packages (RECOMMENDED)”

  2. Hit “Next” or Enter to install..

  3. Add Cygwin Terminal to start menu. Pin this to the taskbar as we will be using this as the main terminal.


B. Crosstool Setup

  1. Open the Cygwin terminal, create a installation directory for crosstools,

    mkdir /cygdrive/c/crosstool

  2. Create a temp dir for the source files

    mkdir /cygdrive/c/crosstool/src

  3. Change directory into the /cygdrive/c/crosstool/src dir and clone the git repo for crosstool

    cd /cygdrive/c/crosstool/src
    Git clone https://github.com/crosstool-ng/crosstool-ng

  4. Pre-install steps:

    ./bootstrap
    ./configure --prefix=/cygdrive/c/crosstool

  5. Install steps:

    make
    make install

  6. Add crosstool to the cygwin path environment. To do this:

  1. Open the bashrc config file using nano:

    nano /home/.bashrc

  2. You need to add the following line to your .bashrc file:

    export PATH="${PATH}:/cygdrive/c/crosstool/bin"

  1. Change directory to /cygdrive/c/crosstool

  2. Delete the /cygdrive/c/crosstool/src directory

  3. Restart the Cygwin terminal and confirm you have installed crosstool successfully:

    ct-ng help


C. Selecting and building your toolchain

  1. Open the cygwin prompt and view the list of sample toolchains provided by crosstool

    ct-ng list-samples

  2. Load a toolchain sample. For example, “ armv8-rpi3-linux-gnueabihf”, a Linux 4.11 and Raspberry Pi 3 cross compiler toolchain

    ct-ng armv8-rpi3-linux-gnueabihf

  3. Build the loaded toolchain. Note, Cygwin is much slower than native Linux so this could take some time. Approx 60 mins.

    ct-ng build


Providing now errors occurred during the above steps, you should now have a set of tools (gcc, g++, make, etc..) that you can use to build C/C++ code on your host Windows machine. You can then upload and run those binary files on the remote Raspberry Pi 3 device.

You can now integrate this native Windows C/C++ toolchain with the IDE of your choice.





Comments