Tuesday, March 19, 2013

Some useful development patterns via the raspberry pi & minecraft

Programming minecraft on the raspberry pi is not just fun, it's also a great chance to learn some of the cool things that can be done from the linux command line.
We're going to look at two problems:
  1. How can I edit files on my raspberry pi using an editor on my pc?
  2. How can I run minecraft on a raspberry pi with a screen connected but without a mouse and keyboard connected?
  3. Minecraft fails to start: something about a problem loading shared library libGLESv2.so
The Setup
  • 1 raspberry pi connected to a network and a monitor
  • 1 PC (I'm using linux, it should work equally well on osx, not sure about windows.)

How can I edit files on my raspberry pi using an editor on my pc?


Create an empty folder on your PC:
mkdir ~/pi
Then use sshfs to mount it
sshfs pi@192.168.1.82: ~/pi/
Where pi is my user name and 192.168.1.82 is the ip address of the pi.
Now, on my pc if I cd to ~/pi I can see the files in the home directory of my pi, which means I can open them on my pc using my editor of choice

How can I run minecraft on a raspberry pi with a screen connected but without a mouse and keyboard connected?


From your pc ssh into the pi specifying -X
ssh -X pi@192.168.1.82
This turns on X11 forwarding - you don't need to know what that means for now, just start minecraft from inside ssh. You should see an empty minecraft window appear
Now take a look at your monitor, you should see minecraft there and be able to use your laptop's mouse and keyboard to move yourself around
As a bonus, you should be able to drag the window around on your pc, and have the window move around on your pi as well

Minecraft fails to start: something about a problem loading shared library libGLESv2.so


When I run minecraft I get this:
./minecraft-pi
error while loading shared libraries: libGLESv2.so: cannot open shared object file: No such file or directory
Shared libraries are essentially bits of code that are shared amongst many programs. You can see what shared objects a program needs by typing
ldd ./minecraft-pi
You might see some stuff marked "not found" at the top
        /usr/lib/arm-linux-gnueabihf/libcofi_rpi.so (0x4022c000)
        libGLESv2.so => not found
        libEGL.so => not found
        libbcm_host.so => not found
        libpng12.so.0 => /lib/arm-linux-gnueabihf/libpng12.so.0 (0x40182000)
        libSDL-1.2.so.0 => /usr/lib/arm-linux-gnueabihf/libSDL-1.2.so.0 (0x40235000)
        libstdc++.so.6 => /usr/lib/arm-linux-gnueabihf/libstdc++.so.6 (0x402c8000)
        libm.so.6 => /lib/arm-linux-gnueabihf/libm.so.6 (0x401aa000)
To help linux find some of these shared object you can specify an option on the command line before you run your command:
LD_LIBRARY_PATH=/opt/vc/lib ./minecraft-pi

1 comment:

  1. Nice but it's better to edit /etc/ld.conf (or /etc/ld.conf.d/somethink) and then run ldconfig instead of using LD_LIBRARY_PATH

    ReplyDelete