1

The way I mostly go about developing for a Raspberry Pi is by writing the code on my main machine in an sshfs directory that corresponds to /home/user on the Pi and then testing it by sshing into the Pi and running it.

This process is a bit tedious to me and I wonder what would be a more effective way of doing it.

It would be nice to have a single command that (cross)compiles the code in case the language I am using requires compiling, copies over the files, runs the program and redirects the console input / output onto my (GNU/Linux) PC.

xuwenbuwer
  • 111
  • 2

2 Answers2

1

If you want to develop C/C++, you can use Eclipse CDT, once installed and with the right toolchain you will be able to code on your PC, then compile on your PC, send the binary file and remote debug. All from your PC without touching the raspberry.

Needed :

  1. Eclipse CDT
  2. Raspberry Linux toolchain (if you can work on Windows there is SYSGCC toolchain)
  3. gdbserver (on the raspberry)

You may find more here : Cross-Compilation for raspberry

1

I'd approach this by trying to craft a Makefile recipe to carry out the steps you want, including passing the binary to be tested as a command to ssh. Something along the lines of (note that this is totally untested and probably overly complicated):

SCP_CMD=scp
SSH_CMP=ssh
HOST_URI=pi@raspberrypi.local
HOST_PATH=/home/pi/bin/
LOCAL_PATH=./
OUTPUT=binary_to_test

.PHONY: transfer remote_execute test_on_remote

test_on_remote: $(OUTPUT) transfer remote_execute


transfer:
    $(SCP_CMD) $(LOCAL_PATH)$(OUTPUT) $(HOST_URI):$(HOST_PATH)$(OUTPUT)

remote_execute:
    $(SSH_CMD) $(HOST_URI) "$(HOST_PATH)$(OUTPUT)"

Obviously you'd need to add some rules here to compile your binary as well. Just typing make should then compile, transfer and run your binary. You may prefer to use rsync instead of scp if, for example, you had supporting files that need copying over as well as the binary to be tested.

A possible alternative to running the binary through ssh for testing might be to install gdbserver on your Pi and start it through ssh and then connect to it with the cross-compiler gdb on your development machine.

Roger Jones
  • 1,484
  • 8
  • 14