Building Raspberry Pi programs on a traditional PC

Conclusion

If you want to write portable code that is easy to adapt for the Raspberry Pi environment, a scripting language such as Perl or Python is the best option. If you prefer the performance edge that comes with writing in a compiled language, and you would want to compile your code on an Intel-based development system, you'll need to get used to working with cross-compilers.

Optimizing for the RasPi 2

The Raspberry Pi actually changed to a new hardware architecture with the arrival of the Rasp Pi 2. Raspberry Pi 2 models use the ARMv7 processor, and earlier versions use the ARMv6. If you wish to optimize the program for the Rasp Pi 2 environment, use the -mcpu=cortex-a7 -mfpu=neon options in the C/C++ and Fortran compiler. The results then run a little faster on the Rasp Pi 2 but they produce the error message Illegal instruction on the first generation Rasp Pi. In Google Go, set the switch via the environment variable export GOARM=7.

When Windows is the Host System

This article deals mainly with cross-compiling on a Linux system, but the process also works on Windows. As long as Mono cooperates, you should invoke C# programs developed with Visual Studio via mono program_name to the Rasp Pi. To cross-compile Go on Windows, you'll need to compile Go from the source code as the cross-compiler. Windows lacks a native C compiler for compiling Go, but the Go community [5] recommends TDM-GCC [6].

With C++ and C, it is a good idea to choose the Sysprogs-Windows-Toolchain for the Raspberry Pi [7] (Figure 1). After setting up the toolchain with default settings, you will find the compiler, along with the necessary tools, in the C:\SysGCC\raspberry\bin\ directory. The system will accept the folder automatically in the path with the corresponding option in the installation assistant.

Invoking arm-linux-gnueabihf-gcc.exe helloworld.c translates a C program under Windows for the Raspberry Pi. Many programmers prefer to work with an Intergrated Development Environment (IDE). IDEs usually have settings where one can setup which compilers should be used – and there you can choose the crosscompilers instead of the native compilers. For example, the CodeLight IDE [8] is available for Linux and Windows.

Figure 1: Installing the Sysprogs Windows toolchain for the Raspberry Pi.

Infos

  1. Raspberry-Pi-Tools: https://github.com/raspberrypi/tools
  2. "What do you mean by soft float ABI and hard float ABI?": http://raspbian.org/RaspbianFAQ#What_do_you_mean_by_.22soft_float_ABI.22_and_.22hard_float_ABI.22.3F
  3. Linaro: https://www.linaro.org
  4. Google Go: https://golang.org
  5. "Installing Go from source": https://golang.org/doc/install/source
  6. TDM-GCC: http://tdm-gcc.tdragon.net
  7. "Sysprogs Windows Toolchain for Raspberry/PI": http://gnutoolchains.com/raspberry
  8. CodeLite Development Environment: http://www.codelite.org
  9. Code for this article: ftp://ftp.raspberry-pi-geek.com/pub/listings/raspberry-pi-geek.com/14

The Author

Wolfgang Dautermann works as a system administrator at the FH Joanneum University of Applied Sciences in Graz, Austria. He is busy in the Linux community and serves as one of the organizers for Linux Days in Graz.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content