views:

63

answers:

2

My .deb package, built on 32-bit Ubuntu and containing executables compiled with gcc, won't install on the 64-bit version of the OS (the error message says 'Wrong architecture i386'). This is confusing to me because I thought that in general 32-bit software worked on 64-bit hardware, but not vice-versa.

Will it be possible for me to produce a .deb file that I can install on a 64-bit OS, using my 32-bit machine? Is it just a matter of using the appropriate compiler flags to produce the executables (and if so what are they), or is the .deb file itself somehow specific to one processor architecture?

+2  A: 

The architecture is just an option in the config file of debian package. By default it uses those from uname. You can override it but there is an easier way.

In general, most 32-bit programs will run fine on 64-bit. However, unless you have a very old PC, it is also very easy to install a mini 64-bit debian in a virtualbox virtual machine. You probably only need base + build essentials + dev libraries. This will not take a lot of diskspace. If you can spare 2G diskspace, just install a desktop debian.

There are more options to do crosscompilation, with various degrees of automation.

I use the virtualbox method regularly. It is easy and fast.

If you run 64-bit linux making a 32-bit environment is as easy as mkdebootstrap + linux32 + chroot.

Peter Tillemans
Anything is possible. I have seen solutions with the architecture dependent stuff in separate directories which are selected in the postinst and put in their place with symbolic links. You can also split your package in a shared package and separate architecture dependent pkgs. All these options are 'non-standard-practice' and lead to rework and complicated procedures. It is by far the best option to create 2 packages.
Peter Tillemans
+4  A: 

The deb installer is probably refusing to install your package because it was (correctly) labeled with a conflicting Architecture: field. i386 code can be executed on an amd64 machine, but it requires that all the appropriate dependencies (32-bit libraries, etc.) be present. It's better to build separate packages for each architecture.

Yes, you can build for 64-bit on your 32-bit machine. It's called cross-compiling, and it requires that you create a build environment for that purpose. To get started, you might want to look up the dpkg-cross and apt-cross tools.

Alternatively, you can just install a virtual machine running a 64-bit OS, and build for your secondary architecture there.

Forest