Raspberry PI cross building native (C/C++) graphical applications from Windows

Developing and testing C and C++ applications for the Raspberry can be inconvenient because of slow builds, so it is usually far more interesting to be able to develop in your own box, then just do the final checks in the target platform, in this case the Raspberry PI.

raspberry pi ++

This article shows how to develop an OpenGL based application (using the GLFW library), that will be first built and run in the desktop, then cross-built to the RaspberryPI, using biicode hooks and toolchains features to easily automate the process.

All you need to run this example is to get biicode installed with its C/C++ dev tools (bii setup:cpp). No need to install or configure any other tool, as it will manage to download and install them when required.

We will build the basic GLFW examples:

particlesNote that biicode has retrieved the GLFW source code, it is not in the examples, but as an external dependency defined in the biicode.conf file.

Biicode uses CMake as build system and thanks to the possibility of defining custom toolchains, it is quite simple to define a new one. Sysprogs (http://sysprogs.com/) has created an excellent cross build suite, including R-PI one with gcc4.9 support as well as a complete sysroot. Next commands will download and setup everything we need:

When the GNU Toolchain for Raspberry launches, accept the defaults and the license agreement:toolchain

It will also download and unzip the SmartTTY application that is useful to upload the final binaries to the R-PI.

Once this is done, the cpp:build is still building the Windows desktop version. We can change to the new toolchain that has been created (in bii/rpi_toolchain.cmake) with the following commands:

That will build the same examples, but for the RPI. It is time to upload them to the R-PI, to check if they work. We use here the previously installed SmartTTY:

ssh Go to Menu -> SCP -> Upload a directory. Then select your project “glapp/bin” folder and upload it to the folder you want in the R-PI (eg. /home/pi/glfwexamples)

Then go to the R-PI (you need a connected monitor and keyboard, we are developing a graphical application), launch X if you haven’t, and run the app:

torusYou can switch back and forth between desktop and cross build, very easily:

Note that the block diego/rpiwin, once it installed things, it is no longer necessary in your project, you can safely close it (or delete it)

There is however a problem with these apps, they run on the Raspberry, but they are too slow. This is because we are using the default OpenGL renderer, which uses the CPU instead of the R-PI GPU and thus is very slow. To take advantage of the HW accelerated support of the Raspberry, we should use EGL (GLES v2) instead, but this is the subject of a different post. Please leave a comment if you are interested in it or if you experience any problem while trying these examples. Remember there is a Forum and you can also use the tag “biicode” in StackOverflow

Enjoy!


Related Posts