Home > Uncategorized > Cross compiling for i386 from x64 Ubuntu

Cross compiling for i386 from x64 Ubuntu

January 8th, 2011

I’ve recently been playing with making programs using Qt and c++, overall I’ve been very happy with it, it’s a nice clean API and very nice to work with. I do most of my development on either my desktop machine or my laptop, both of these run the 64-bit version of Ubuntu Maverick Meerkat. I also have a Acer Aspire Revo, running Ubuntu Maverick Meerkat but this computer is running the 32-bit version. I wanted to get some of my Qt programs running on the Revo but didn’t want to install all the development packages and compile on there (it’s a little slow for compiling code and the screen on my main machine is nicer :-D), so I set about working out how to cross compile my applications to run on 32 bit linux from 64 bit.

The easiest way to do it seems to be using pbuilder to create a 32 bit chroot environment, install all the development packages in there and then compile there. So how do we go about doing that? Well here’s some simple instructions…

First of all we need to install pbuilder and it’s dependencies so first of all run…

sudo apt-get install pbuilder

Now we want to create the 32 bit chroot environment…

sudo pbuilder create --debootstrapopts --arch --debootstrapopts i386

This takes a while to create and requires the downloading and installing of a number of packages. Once this is complete the chroot environment will be setup. We now want to login to the environment and install the extra packages needed to build our application. By default when you exit pbuilder sets the chroot environment back to how it was when you entered, as we don’t want to have to install these packages every time we go in we add an extra parameter to tell it to save any changes we’ve made when we exit.

sudo pbuilder login --save-after-exec

Now we’re in the chroot environment we’ll install the packages needed for development, I needed a couple of packages from universe so enabled it with…

echo "deb http://gb.archive.ubuntu.com/ubuntu/ maverick universe" >> /etc/apt/sources.list
apt-get update

As I was playing with building 32bit .deb files for my applications that use qt-webkit and vlc I installed the following packages (along with some extras like subversion, vim and openssh-client for convenience) with apt-get…

apt-get install build-essential autoconf automake autotools-dev dh-make debhelper devscripts fakeroot lintian pbuilder libvlc-dev libqtwebkit-dev vim openssh-client subversion

Once this completed I made a couple of other changes that I wanted to persist between chroot sessions (copying in gpg keys, etc) and then exited the chroot environment with…

exit

This should take a little while as the system compresses the chroot environment so the changes you made persist between sessions. Now whenever you want to go into the chroot to compile just run…

sudo pbuilder login

Incidentally, if you want a good simple tutorial on createing .deb files you wont go wrong looking at this one.

Be Sociable, Share!
Comments are closed.