Sunday, January 22, 2012

Building a program which uses existing libraries

For this, we're going to build nsnake, which requires the ncurses-devel set of precompiled libraries.

Note: While you're reading this tutorial, you'll see me exit the terminal a lot... I do that so that when I start the next section, it's always with a fresh terminal window, so everyone is in the same directory. You don't HAVE to do that, but that's why I do it in these tutorials.

Download the nSnake Source
Go here, to download a copy of nSnake (as of this writing version 1.5 is the latest):
http://sourceforge.net/projects/nsnake/files/

Save the file to your Downloads directory. You can get there by clicking on Places -> Downloads

Add caption
Move the source to your build directory:
Open your build directory Places -> Home Folder
Then double-click your build directory

Open your Downloads directory.
Double-click nsnake-1.5.tar.gz to see its contents
Drag / drop the nsnake-1.5 directory into your build directory


Changing permissions to allow the installation of precompiled ARM libraries:
These steps are required due to a bug in the current virtual machine (0.2). The VM creator is aware, so these will likely not be required in future versions of the development VM:
Double-click the Raspberry Pi Development icon

Go to the ARM emulator root file system
cd ../raspberry_pi_development/f13arm-rootfs

Open the permissions on the folders WAY up. It will ask you for a password
sudo chmod -R 777 *
[sudo] password for raspberry:

The administrator password is:
password

Close that terminal window by entering:
exit


Compile for x86 / Linux
Double-click the Raspberry Pi Development icon
In the terminal window, go to the nsnake-1.5 directory
cd nsnake-1.5

Then, make the application by entering:
make

You can then run the program by entering the following command:
./bin/nsnake


Have fun, and play a round or two, you've earned it! Press Q at the main menu to quit.

Once you're done playing around, you can close the terminal by entering:
exit

Download the precompiled libraries for ARM
Ok, so the Linux VM that you're working with has all of the precompiled libraries needed already installed on it. However, the ARM emulator does not, which means nSnake will NOT compile correctly in SB2. We need to download a precompiled library before we go anywhere.

Double-click the Raspberry Pi Development icon
Enter the following to have Scratchbox make the ARM version of the precompiled ncurses-devel library available:

sb2 -eR yum install ncurses-devel

You'll get a confirmation prompt or two. The answer is:
y


Leave the current terminal by entering:
exit

Compile for ARM

Double-click the Raspberry Pi Development icon

Change to the nSnake directory
cd nsnake-1.5

Re-make the application for ARM. In this case, I'm going to use the -B switch (case sensitive!) which will cause the whole application to re-compile from scratch. Why? Well, the current intermediate files (which are still valid / up-to-date) are in the wrong file format (x86 instead of ARM). If you try just a straight make, it will fail. -B will insure all intermediate files are compiled into ARM binaries.

To make nSnake for ARM, and forcing all fresh intermediate files, enter:
sb2 make -B

One more step before you run the ARM version: You need to set an environment variable for compatibility/emulation reasons. In your terminal window, enter:

TERM=linux

Then, as you'd expect at this point:
sb2 ./bin/nsnake

Enjoy, your game!

No comments:

Post a Comment