Raspberry Pi, C++, and X

Cross compiling to the Pi has turned out to be difficult for a number of reasons I outlined in this post. I was on the verge of giving up C++ for the pi in favor of Python which, whilst slightly slower for the 3D stuff would at least allow me to avoid these cross compilation nightmares.

I have a very specific development configuration that I want to maintain between my mac and my raspberry pi. I want to use Sublime Text to edit the code on the mac, and ssh to remote into the pi. Then, I want to be able to compile the code on the Pi and run it whilst displaying the Pi output on my second monitor. And, I want to be able to do all of this without cluttering my desktop with an additional keyboard and mouse. In the end, this is all possible using the magic of networked X windows. Here’s how I did it:

1. Edit code on your mac in your favorite text editor. I use Sublime Text 2

2. Use Panic’s Transmit to copy files to the pi using SFTP. When I’ve updated the source, I do a quick “rm -r BIMBox” on the pi to trash the pi version of the app. Transmit has a problem overwriting files on the pi sometimes. This is not the optimal way to do this, because then Make has to rebuild the entire program as opposed to being smart about only updating the stuff you’ve worked on. This will be problematic once the source is more hefty than it is, but this works for now. I keep the transmit window open next to a Finder window containing the directory of my source, then just drag and drop the whole thing onto the pi.

3. Ssh into the pi using the following :

ssh -X pi@raspberrypi.local

The -X flag will tell ssh to enable X windows forwarding.

4. Once logged into the pi, at the command line type:

/etc/X11/Xsession&

The ‘&’ will tell X windows to run in the background, returning you to the pi’s command line. When you run X windows in the background on a mac, it takes “background” quite literally and shows the wheezy desktop underneath your mac desktop. Very strange. But, because we’re not going to be interfacing with the Pi’s desktop, you don’t have to worry about this.

5. From the Pi’s command line, you can compile your software on the pi.

6. With your Pi’s HDMI output pluggged into a secondary display, upon running your program the Pi wakes up the second monitor. I’m still working with John Macey’s piNGL library for 3D and I’ve added SDL to take take keyboard and mouse inputs. When the main app runs it creates the primary window on the secondary monitor but leaves a blank window on the primary monitor. This behavior doesn’t exist when I run without networked X windows, but it works in my favor when running X windows networked because SDL then tracks your mouse across this blank window as if it were the main window of the application.

Comments are closed.