jeff's picture

All of our systems are 64-bit, but today I needed to compile a simple executable for a 32-bit system. Fortunately gcc makes that easy; just add the "-m32" switch to the command line. Unfortunately, it didn't work!

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.2.4/libgcc.a when searching for -lgcc
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.2.4/libgcc.a when searching for -lgcc
/usr/bin/ld: cannot find -lgcc
collect2: ld returned 1 exit status

I've got the various "lib32" files installed so I can run 32-bit apps on my 64-bit system, but it turns out you need a couple more to actually compile 32-bit apps.

Here's what you need to do on Ubuntu Hardy. (It's probably the same package names on most recent debian or debian-based systems)

sudo apt-get install gcc-multilib libc6-i386

That will pull in the necessary files and the "-m32" switch works. Voila!