This post is an annex to the Meditech project explaining one of the (possible) best practices to setup an efficient development environment for C++ developing on the Raspberry PI platform with the advantage of an advanced IDE and remote compiling without emulators.
Why a development IDE
When C/C++ language programming covers a large part of an embedded project going far beyond the simple cut and paste of some examples, to be able working in a good development environment represent a success factor for code quality and usability; adopting a high level programming IDE become a must at least for the following reasons:
- Availability of optimized editing tools, including language syntax-checking
- Fast moving between sources and headers inside a well organized project
- Easy accessibility to classes, function declarations, constants, commenting
- Fast syntax checking and bug-tracking
- Sources and headers organization in projects
- Optimized compiling feedback and fast error checking
- Local and remote sources replication in-synch
Note that the use of a PC with a high level IDE creating code for different platforms (mostly embedded devices) where it is difficult or impossible to develop it is a widely diffused practice. This is the way adopted at least for the following well-known devices:
-
- All Android based devices
- Symbian devices (already diffused in the Indian and some south-world countries)
- iOS smartphones and iPad
- Arduino
- ChipKit and many PIC based microcontrollers
- Many other SoC and SBC
These and many other factors dramatically increases the productivity and the quality of the final result when working with a remote compiling enabled IDE.
What IDE for the Raspberry PI
The first assumption is that the Raspberry PI linux (here it has been used raspian but the concept is the same with other distributions) should not host the development environment as it is the target of the project. So we should think to the better way to manage the code development on a PC seeing the result real-time on the target device. In few words, we will provide a simple network connection between the Raspberry PI and the development PC; we can use the WiFi, the LAN connection, the home router or any other method so that the two machines can share their resources on the network.
The other assumption is that for the best result it should be possible to compile remotely with few simple operations, fast checking errors and compilation results in the IDE on the PC, running the program over the native platform.
The two most popular open source IDE for multi-language development are Eclipsehttp://www.eclipse.org/ and NetBeanshttps://netbeans.org/. There is an alternative to the remote compilation using a cross-compiler: with a particular settings it is possible to compile on a different hardware architecture (i.e. a PC with a Intel-based CPU) the code that should run on the Raspberry PI that is, an ARM based architecture. It is a more complex way with so few advantages that where it is possible it is best to avoid this method.
Just an interesting note: the PC Arduino IDE represent a good effort in this direction, as well as the MPIDE supporting also the ChipKit PIC based platforms. It is a simple (and a bit primitive) IDE making a cross-compilation of the program before uploading the binary file to the micro controller board.
I am used to base many of my developments on the Eclipse IDE as this is one of the privileged Android, Java and Php develompent tools. Unfortunately after some tests I saw too many issues when trying to connect the networked Raspberry PI for remote compiling so I adopted the NetBeans IDE supporting a very simple setup.
Minimal requirements for remote compiling
There is a series of minimal requirements that should be accomplished to remote compile C++ programs on the raspberry PI; most of these are obvious but a reminder can be useful:
- SSH and SFTP installed on the Raspberry PI for remote access (this option can be enabled from the raspi-config setup utility)
- GNU compiler (better to check the system upgrade for the last version of the compiler, assembler and linker)
- SSH access to the Raspberry PI from the PC
- Development version of the C++ libraries needed for your needs, correctly installed on the Raspberry PI
NetBeans IDE setup on the PC
These notes refers to the version 8.0 of the Netbeans IDE; If a different (maybe newer) version is installed maybe you find some minor changes in the menu settings.
To install a copy of the IDE on your PC it is sufficient to go to the NetBeans IDE platform download page downloading the last available version for yourplatform (Mac, Windows or Linux)
The installation is simple and in most cases the default settings are all what you need.
When the installation process end, few things should be changed from the Settings menu. Its location can vary depending on the PC platform you are using; in the Mac OSX it is in the pull-down NetBeans main menu (the topmost left choice) while in Windows and Linux maybe in the File menu.
From the settings windows (see the image above) you can customize all the features of the IDE, e.g. the editor behavior, source font and colors, the graphic appearance and so on. From the C/C++ option tab select the GNU compiler (it should be the default, else add it updating the IDE with the Add button on the same window).
Againfrom the same window you should Edit the host list (by default there is only localhost, the development PC) adding the parameters to connect with the Raspberry pi:
- Add the user (in this case the default user pi)
- Add the password and confirm to save it avoiding to repeat it every time the IDE starts connecting to the Raspberry PI
- Insert the Raspberry PI IP address (better to set a static IP instead of a DHCP assigned to avoid the IP changed the next time you reopen the IDE)
- Specify the access mode SFTP (that is, FTP protocol over SSH connection)
- Enable the X11 (the linux graphic server) forwarding
That's all!
Starting developing
With the IDE set in this way you can start creating a new project and write your code. On the IDE top toolbar there is the connection button to activate the remote connection with the Raspberry PI. To compile remotely from the PC you should be connected. As the device is remotely connected NetBeans gives you the option to edit the application sources locally but when you Build the application the sources are automatically zipped, sent to the remote device (the Raspberry PI), unzipped and compiled. Errors and messages are shown in the Build result window making the debug very simple.
Another very useful feature is the option to open a remote terminal directly from the IDE. In this way, as shown in the following screencast, the development lifecycle included the program running and testing become very simple and efficient with a minimal effort.
Top Comments