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.

  • Why not just write a script that a) compiles/builds on the local host, b) uses scp to copy the files over, c) SSHs into the Pi, d) runs the program? The terminal window can be kept open until after program has finished running on the Pi. – stevieb Feb 8 at 16:31
  • 1
    MS Visual Studio can do the cross compile and deployment even when the Raspberry is running Linux. youtube.com/watch?v=XIiFuBczd6A – Dougie Feb 8 at 17:58
  • But I use Gentoo. – IronPig Feb 8 at 18:01
  • Gentoo is a Linux flavor/distro – MatsK Feb 8 at 19:03
  • Have you tried Jenkins? – DarkHeart Feb 19 at 21:50
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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.