uri34
Posts: 4
Joined: Fri Apr 15, 2022 9:46 am

Cross platform build project for RPi ZeroW ...

Tue Jun 28, 2022 9:26 am

Good day !

There is a cross-platform setup for building and debugging a project for Ps4 from a Linux workstation ! Everything works as it should ! At the moment , there is a need to rebuild the project also for RPi ZeroW(ARMv6) ! Who can advise how to set up a joint project build for RPi4(ARMv8) and Re ZeroW(ARMv6) ? I understand that this is possible, but having spent a lot of effort on web surfing, I have not yet achieved the result ...

tttapa
Posts: 86
Joined: Mon Apr 06, 2020 2:52 pm

Re: Cross platform build project for RPi ZeroW ...

Tue Jun 28, 2022 5:44 pm

You basically need three things:
  1. A cross-compilation toolchain, with the compiler, linker and other binary utilities;
  2. A sysroot with the system libraries and your third-party libraries, including headers and ARM-versions of the libraries to link against;
  3. A build system (or build system generator) that easily supports cross-compilation, e.g. CMake.
For the toolchain, you have many options. I use these ones: github.com/tttapa/docker-arm-cross-toolchain
You can also get the gcc-arm-linux-gnueabihf from your system's package manager, but keep in mind that it might be outdated, and that it might not support ARMv6.

Depending on how many dependencies you have, you can either copy the toolchain's basic sysroot, or you can create a full-fledged Raspberry Pi OS sysroot that you can apt-install your dependencies into.
The toolchain's sysroot for the toolchains I linked above can be found at x-tools/aarch64-rpi3-linux-gnu/aarch64-rpi3-linux-gnu/sysroot. Simply create a copy of that folder and make it writable (chmod -R +w your_copy_of_the_sysroot). Then cross-compile your dependencies and install them into your sysroot. This can be a huge task, depending on how many dependencies you have. In many cases, I would therefore recommend using a package manager to handle your (cross-) dependencies. If you're on Ubuntu, you can simply create a Raspberry Pi OS sysroot that includes the apt package manager (one that you can run on your workstation but that installs ARM versions of the packages into your sysroot). Full instructions can be found here: https://tttapa.github.io/Pages/Raspberr ... ent-RPiOS/

Finally, configure your build system for cross-compilation using the toolchain you installed and the sysroot you created. For CMake, simply create a toolchain file and pass that as an argument when configuring the project. You can find example toolchain files in https://github.com/tttapa/RPi-Cross-Cpp ... ster/cmake, and detailed instructions/explanations in https://tttapa.github.io/Pages/Raspberr ... oject.html

There are also instructions for remote debugging, see https://tttapa.github.io/Pages/Raspberr ... gging.html.

Note that you need a different toolchain, sysroot, and CMake toolchain file for each system (one for ARMv6 and one for ARMv8/AArch64). For the RPi4, use the same toolchain as for the RPi3 (they're both ARMv8). For optimal performance, you can create a specific CMake toolchain file for the RPi4 that sets the -mcpu=cortex-a72 flag.

uri34
Posts: 4
Joined: Fri Apr 15, 2022 9:46 am

Re: Cross platform build project for RPi ZeroW ...

Sun Jul 03, 2022 7:48 am

Good afternoon !
Thank you for your reply !
Do I understand correctly that to compile in QT Creator for RPi ZeroW (ARMv6), unlike RPi4 (ARMv8), a completely separate configuration is needed ?!
That is, almost the same isolated toolchain as if I were setting up cross compilation for another (non-RPi) platform ?
And there is no way to tell an already installed compiler to compile for the target ARM6 platform ?

tttapa
Posts: 86
Joined: Mon Apr 06, 2020 2:52 pm

Re: Cross platform build project for RPi ZeroW ...

Sun Jul 03, 2022 10:28 am

uri34 wrote:
Sun Jul 03, 2022 7:48 am
Do I understand correctly that to compile in QT Creator for RPi ZeroW (ARMv6), unlike RPi4 (ARMv8), a completely separate configuration is needed ?!
Indeed, different architectures require different compilers, different start files, libraries etc.

The configuration files you need aren't that different. If your build system supports cross-compilation well, having one 10-line configuration file for each target platform shouldn't be an issue. Especially since you're probably going to be testing on one platform at a time.
uri34 wrote:
Sun Jul 03, 2022 7:48 am
And there is no way to tell an already installed compiler to compile for the target ARM6 platform ?
There are toolchains that include the necessary files for multiple architectures, but none of the ARM cross-compilers I've come across in the past years (in the Ubuntu and Debian repos, from the ARM website ...) had support for both ARMv7 and ARMv6. Even when explicitly adding flags to compile for ARMv6, you still get an ARMv7 binary.

In theory, you could use 32-bit ARMv6 on all systems, the newer CPUs still support it. This is what allows Raspberry Pi OS to support the RPi1 through RPi4 using the same images.
The downside is reduced performance, and this won't work on a 64-bit system unless you install 32-bit versions of all supporting libraries. In other words, it's probably best and easier for your users to provide specific binaries for each platform.

uri34
Posts: 4
Joined: Fri Apr 15, 2022 9:46 am

Re: Cross platform build project for RPi ZeroW ...

Tue Jul 05, 2022 11:56 am

I am very grateful to you for the answers with your explanations !
They are very important to me !
Apparently I will have to install a separate (for ARM6) toolchain! Add and configure it for use with QT-Creator !
Of course I wanted to outwit nature, but it seems that my desires are excessive ! :)
I will try ...

Return to “C/C++”