Compiling C/C++ program for the OLPC: Difference between revisions
No edit summary |
No edit summary |
||
(10 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
'''Note:''' The instructions here are valid for x86 based OLPCs, i.e. the OLPC 1.0 and 1.5 models. OLPC 1.75 is ARM based, and you will need a cross compiler setup e.g. based on [http://www.scratchbox.org/ scratchbox]. That is outside the scope of this note. |
|||
= Background = |
= 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. |
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 chroot OLPC environment = |
||
Line 12: | Line 16: | ||
su |
su |
||
mkdir /home/olpc/ |
mkdir -p /home/olpc/devp |
||
cd /home/olpc/ |
cd /home/olpc/devp |
||
mkdir dev |
mkdir dev |
||
mknod dev/null c 1 3 |
|||
⚫ | |||
chmod 0666 dev/null |
chmod 0666 dev/null |
||
⚫ | |||
mkdir src |
mkdir src |
||
Line 23: | Line 28: | ||
su |
su |
||
cd / |
cd / |
||
rsync -a bin sbin lib usr etc desktop:/home/olpc/ |
rsync -a bin sbin lib usr etc home var desktop:/home/olpc/devp |
||
scp proc/cpuinfo desktop:/home/olpc/ |
scp proc/cpuinfo desktop:/home/olpc/devp/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). |
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: |
* Now chroot into this new enviroment on the desktop: |
||
chroot /home/olpc/ |
chroot /home/olpc/devp |
||
* In the chroot jail we can now set up the development environment through yum. To compile FBReader I needed to do the following installations: |
* 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 |
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. |
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 |
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 == |
== su in the chroot jail == |
||
If you feel uncomfortable working as |
If you feel uncomfortable working as 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: |
See: |
||
Line 52: | Line 58: | ||
-- [[User:Dov]] |
-- [[User:Dov]] |
||
[[Category:Software development]] |
|||
[[Category:Developers]] |
|||
[[Category:Programming language]] |
Latest revision as of 18:16, 5 May 2012
Note: The instructions here are valid for x86 based OLPCs, i.e. the OLPC 1.0 and 1.5 models. OLPC 1.75 is ARM based, and you will need a cross compiler setup e.g. based on scratchbox. That is outside the scope of this note.
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 -p /home/olpc/devp cd /home/olpc/devp mkdir dev mknod dev/null c 1 3 chmod 0666 dev/null mkdir proc mkdir src
- On the olpc do:
su cd / rsync -a bin sbin lib usr etc home var desktop:/home/olpc/devp scp proc/cpuinfo desktop:/home/olpc/devp/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/devp
- 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 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:
Good luck!
Please let me know if you found this info helpful, e.g. in my Discussion page.
-- User:Dov