Developing 32 bit apps under 64 bit Linux (Ubuntu)

From Code::Blocks

Introduction

The purpose of this guide is to provide step-by-step instructions on how to build 32-bit applications under a 64-bit Linux OS; it has been tested with Ubuntu Karmic Koala (9.10).

Required software

The main packages to do the trick are the multilib versions of g++ and gcc:

 
g++-multilib
gcc-multilib

(Install with synaptic or sudo apt-get install)

You'll also need the .deb 32 bit packages for your Linux distributions - download using your browser, not synaptic:

libwxbase2.8-0_2.8.10.1-1_i386.deb
libwxbase2.8-dbg_2.8.10.1-1_i386.deb
libwxbase2.8-dev_2.8.10.1-1_i386.deb
libwxgtk2.8-0_2.8.10.1-1_i386.deb
libwxgtk2.8-dev_2.8.10.1-1_i386.deb
wx2.8-headers_2.8.10.1-1_i386.deb
wx2.8-i18n_2.8.10.1-1_all.deb
wx-common_2.8.10.1-1_i386.deb

For jaunty, for instance, you'll find them at http://apt.wxwidgets.org/dists/jaunty-wx/main/binary-i386/.

This is important, if you use synaptic or apt-get to get the binaries, you'll only see the 64-bit versions.

Preparing the system

Unpack each of the downloaded .deb files (using the archive manager, not gdebi!), and then for each unpack the data.tar.gz file. You'll probably have to unpack each .deb package to its own directory, and then merge the unpacked directories together. You'll just need the include and lib directories.

They can't be installed with gdebi or other package manager, because they will (correctly) show as a wrong architecture, and even if it did, things would probably go to the wrong places.

Create the directory structure and move files:

- Move the directory ./lib to /usr/lib32

- Create an i32 directory under /usr, and create the following structure under it:

/lib
   /wx
      /include

- Move the ./include directory to /usr/i32, so now you'll have this:

/usr
   /i32
      /include <--- that's where the 32 bit include files go
      /lib
         /wx
            /include

- cd to /usr/i32/lib/wx/include

- Make a symlink there to /usr/lib32/wx/include/gtk2-unicode-release-2.8

Now the complete tree should look like this:

/usr
   /i32
      /include
         /wx2.8
      /lib
         /wx
            /include
               /gtk2-unicode-release-2.8 <--- the symlink you just created

Setting the build options in Code::Blocks

Select the menu Project|Properties and then copy the desired build configuration, renaming it accordingly (like Release32, for instance). Don't forget to edit the directories for the executable and obj files, otherwise you'll overwrite your previous build (or worse).

You'll have to remove the build options from the overall project to the specific options you created, that is, the compiler/other options and linker/other options have to be erased from the top level and copied to the Debug and Release build options.

Then, set them for the new build target as follows: - compiler/other options:

-m32 `wx-config --prefix=/usr/i32 --cflags`

- linker/other options:

-m32 `wx-config --libs`

And that's it.

Final remarks

Loading the mulitilib support packages allows you not only to build, but also run the 32 bit apps under your 64 bit system.

If you use additional packages, other than the basic stuff needed to create a wxWidgets app, you will have to either locate existing 32 bit distributions of the corresponding libraries or rebuild them with the -m32 option for the compiler and linker (and possibly other tools, I don't know).

Hope this helps.

Kencamargo 23:39, 30 January 2010 (UTC)