Posts: 9
Joined: Thu Apr 07, 2016 2:40 pm

What to install under Ubuntu to cross-compile for a Pi4 running Raspbian "buster"?

Mon Jan 13, 2020 10:00 pm

I would like to build the source code on a PC running Ubuntu 18.04, to then deploy the executable to a Pi4 model B running Raspbian/Debian 10 "buster".

What should I install on the Ubuntu PC in order to do this? I expect I must install gcc and c++ compilers for ARM and some libraries, but I don't know what are the correct packages to be installed.

User avatar
Posts: 6049
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: What to install under Ubuntu to cross-compile for a Pi4 running Raspbian "buster"?

Tue Jan 14, 2020 12:16 pm

There are many many guides for cross compiling and everyone does it slightly different.

Simplest one: https://hackaday.com/2016/02/03/code-cr ... pberry-pi/
But this does not give you access to any Raspbian libraries/header, only standard C/C++, but installs compilers from repo.

Another example here: https://mechatronicsblog.com/cross-comp ... pberry-pi/

You should only focus on step 3 (toolchain) and 4 (libraries) and you need to understand the link between step 1 and 4.
This guide prefers to just download the tools into a folder instead of installing packages, so you have to tell your IDE or makefile system to use those tools there instead of the system compilers. And you need to tell the compiler to use the Raspbian libraries in the "sysroot".

There are also ways of creating the sysroot from a Raspbian imagefile instead of copying it from a running Pi.

Return to “C/C++”