We no longer use this approach and this page may be out of date – it is left here for archive puropses.  We now use NetBeans for C/C++ development on the RPi, see here.

Using A Windows PC to develop C code for your Raspberry Pi can be done.

These notes on how to do it below are based very much on Alessio Placitelli's great guide which details the steps required and you may wish to follow his original guide instead.

Note that Eclipse is not for the faint hearted! It is a very powerful but very complex programming IDE which can easily confuse the hell out of you and have you banging your head against a wall for hours if it doesn't just work, often because something has changed requiring some new set-up step to make things work as before or work the same on your system compared to the system of someone who has created a set-up guide (just like this one!). The be fair to Eclipse, this isn't so much it being a bad program (actually once setup right its fantastic to use), but more that it is designed to be used in a wide range of situations rather than being a manufacturer produced self configuring software package for a single specific use like many other programming IDE's.  If you are new to C programming by all means give this set-up a go, but if it doesn't work out it isn't just you – loads of perfectly competent programmers have problems understanding Eclipse and the tools it connects with well enough to make it work right for them! Following our Geany based guide is a much easier and simpler way to get up and running with programming in C on the Raspberry Pi if Eclipse defeats you for now.

One other word of warning – this solution uses a cross compiler, which is how you are able to compile on an Intel platform for the ARM based Raspberry Pi.  This is fine if you are using the standard C libraries and maybe one or two additional libraries you can manually copy over such as the RPI IO pin library, SQL server library.  However its a major problem if you want to use libraries with a large number of dependent libraries, for instance programming GTK+ applications, as the libraries are not part of the cross compiler and you need to get pretty advanced dealing with how to copy them over so eclipse can reference them.  At this point its a bit easier if you are using eclipse on a Linux OS but its still a major problem as Linux on a PC will be running on Intel not ARM so the libraries are different. If you want to do programming like this  you will either need to find a way of getting the library files passed to eclipse from the RPi or instead work on the RPi itself and accept its hardware limitations (the fact that the compiler just works with all its installed libraries vs being slower to use than a general PC).

That all said, getting eclipse working as described below is very cool and very productive, but best to be informed up front rather than finding out the hard way!

Setting Up Your Windows PC

Setup Cygwin on your machine

Cygwin gives your Windows machine the Linux functionality needed.

Download the setup.exe file from here and store it in a folder called "c:\cygwin"

Run it (right click and select Run as administrator – we're not sure this is needed, but we ran into problems with our first installation and tried this on a subsequent successful installation which worked)

At the 'Select Packages' page ensure the following are set to install:

  • Python >python: Python langauge interpreter
  • Shells > bash: The GNU Burne Again SHell
  • Shells > mintty: Terminal emulator with native Windows look and feel
  • Devel > make: The GNU version of the 'make' utility
  • Devel > binutils: The GNU assembler, linker and binary utilities
  • Devel – entire folder (we're not sure this is actually needed, but we ran into problems with our first installation and tried this on a successful subsequent installation instead of just make and binutils to ensure everything was present).
  • Debug – entire folder (we're not sure this is actually needed but added it on our installation just in case – however if you are short on disk space leave it out ande see how you go as it adds a few GB of files.).
Install the cross-compilation toolchain

This allows us to use windows but to compile and debug software which runs on the Raspberry Pi ARM.

Download the hardfp version (arm-unknown-linux-gnueabi-hardfp-gdbV1.zip) of the toolchain kindly shared by IanLinsdell, available from his github account. Note that if you don't have git software click the ZIP download button to get the files.

Unzip it into C:/cygwin/opt/cross/x-tools so that the full path is like this C:/cygwin/opt/cross/x-tools/arm-unknown-linux-gnueabi.

Note that this must extract without errors – if you get a filename too long message extract it to a directory straight off C:\ and move it afterwards

Install PuTTY

PuTTY is used to communicate with the Raspberry Pi using SSH.

Download the windows installer for PuTTY from here.

Use Alessio Placitelli's nifty little hack to create a script which run as a post-build step in Eclipse to upload the file to the board using SSH and executes a few commands.

Save the following as "C:\eclipse\deployment_scripts\rpi_deploy_debug.bat"


@echo off
 
rem Check for a valid filename
IF "%1"=="" (
    ECHO You have to provide a valid source file.
    EXIT /b
)
 
IF "%2"=="" (
    ECHO You have to provide a valid destination path.
    EXIT /b
)
 
SET PUTTYSCP_BIN="C:\Program Files (x86)\PuTTY\pscp.exe"
SET PUTTY_BIN="C:\Program Files (x86)\PuTTY\putty.exe"
SET RASPBERRYPI_ADDR=192.168.0.123
SET USERNAME=pi
SET PASSWORD=raspberry
SET CMD_FILENAME=commands.sh
 
rem Upload the file to raspberry pi
%PUTTYSCP_BIN% -pw %PASSWORD% "%1" %USERNAME%@%RASPBERRYPI_ADDR%:"%2"
 
rem Build a list of actions to do on the pi (chmod, execute GDB server)
if exist %~dp0%CMD_FILENAME% del %~dp0%CMD_FILENAME%
rem echo rm "%2" >> %~dp0%CMD_FILENAME%
echo chmod +x "%2" >> %~dp0%CMD_FILENAME%
echo gdbserver :3785 "%2" >> %~dp0%CMD_FILENAME%
 
rem Execute the action list on the raspberry pi
%PUTTY_BIN% -pw %PASSWORD% -m %~dp0%CMD_FILENAME% %USERNAME%@%RASPBERRYPI_ADDR%
 
exit /b %ERRORLEVEL%

Edit the file as follows:

  • PUTTYSCP_BIN – The full path to pscp.exe, part of the Putty bundle, used to securely copy files over a SSH connection.
  • PUTTY_BIN – The full path to putty.exe, part of the Putty bundle, used to execute commands on a remote host over a SSH connection.
  • RASPBERRYPI_ADDR – The IP address of the Raspberry Pi
  • USERNAME – The username of the user who will authenticate on the Raspberry Pi
  • PASSWORD – The password
  • CMD_FILENAME – The name of the file which will contains all the commands to be executed on the Raspberry Pi (don’ change, it’s not really needded)
Install Eclipse IDE for C/C++ Developers

Download Eclipse IDE for C/C++ Developers (CDT) from here.

Store it in a folder, for instance "c:\eclipse\eclipse_v#_#"


If you don't have it you also need to install the java runtuime environment (see the readme folder)

Run eclipse by running the eclipse.exe in the folder.

Setup On The Raspberry Pi

Enable The Raspberry Pi SSH Server

The RPi needs to be running a SSH server so we can upload the binaries we compile to it. If you are using the Raspbian OS run this at the command prompt and turn the SSH Server on:

sudo raspi-config

With the SSH server running you can access the Raspberry Pi command line from your Windows machine using a SSH terminal.

Raspberry Pi IP Address

To see your Raspberry Pi IP address type:

ifconfig

If your Raspberry Pi has a new IP address see here.

Other Solutions

gurucoding.com

Cross Compiling Tools

Cross compiling applications which use external libraries needs all of the necessary libraries to have been cross-compiled from source so they can be included in the build process. Many larger libraries (e.g. GTK+) also depend on other libraries that must also have been cross compiled. This isn't a problem when compiling on the RPi as it can just get the libraries using apt-get all ready to use on its ARM architecture, or get them and then compile them on its own target platform.  But if you are using eclipse on a windows or linux PC, the libraries won't be the same as even your linux PC will be Intel not ARM.  The solution here is to either resort to compiling on the RPi which defeats the purpose of having moved development off it to a faster platform, having to cross compile each required library and all if its dependencies manually, or finding a way to just copy the necessary library files over from the RPi.

Some tools which are designed to help with cross compiling large projects with external libraries:

Scratchbox
Scratchbox2
Buildroot

For info on copying the necessary library files over see here.

 

 





USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.

Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.