Compiling C/C++ program for the OLPC

From OLPC
Revision as of 17:01, 26 January 2008 by Dov (talk | contribs)
Jump to navigation Jump to search

Background

Last week I found a bug in the FBReader program and I wanted to compile a new executable for my OLPC with my bugfix. Unfortunately my development system is already updated to Fedora 8 and the executable that I get contained dependencies on shared libraries that only have older versions on the OLPC. This is not very surprising. But the question was how to create a development environment that easily lets me create executables with the correct shared library dependencies. I'm sure there are several method, but the method I used is based on chroot, and should work on any modern Linux based distribution.

Note: This assumes that you do not wish to use the XO itself to compile. Compiling on the XO is entirely possible. Normal C programs can be compiled without trouble. Projects involving C++, especially if also using Boost, may require shutting down the GUI ("telinit 3") to free up some RAM or the addition of swap space. You may install the normal development tools with a command such as "yum install gcc make cvs subversion libX11-devel".

The chroot OLPC environment

The idea is to create a complete copy of the olpc disk contents on my desktop and then chroot into this enviroment. While in the chroot environment I can do yum install to install all the development tools that I need for the compilation.

Here are the exact steps:

  • On your desktop do:
 su
 mkdir /home/olpc/dev
 cd /home/olpc/dev
 mkdir dev/null c 2 2
 mkdir proc
 chmod 0666 dev/null 
 mkdir src
  • On the olpc do:
 su
 cd /
 rsync -a bin sbin lib usr etc home desktop:/home/olpc/dev
 scp proc/cpuinfo desktop:/home/olpc/dev/proc

where desktop is the ip of your desktop. (You will also have to take care of the permissions of the copying through user@desktop or by using chmod). This copies all the os files as well as makes a virtual copy of proc/cpuinfo that yum/rpm needs.

  • Now chroot into this new enviroment on the desktop:
 chroot /home/olpc/dev
  • In the chroot jail we can now set up the development environment through yum. To compile FBReader I needed to do the following installations:
 yum -y install gcc gcc-c++ gtk2-devel make bzip2-devel \
   libz-devel libjpeg-devel

Your milage my vary, but for a gtk program the dependencies above seem resonable.

That's it more or less. You can now develop and compile software in the chroot jail and then copy it over to the OLPC and be pretty sure that the dependencies are correct.

su in the chroot jail

If you feel uncomfortable working as the root in the chroot jail then you can su to the user olpc. Unfortunately this does not work as the fedora 7 su program uses PAM authentification. One way to get around this is to grab coreutils and recompile it, and copy the resulting su executable to /bin/su.

See:

http://tjw.org/etded/su.php

Good luck!

Please let me know if you found this info helpful, e.g. in my Discussion page.

-- User:Dov