Search code examples
ubuntu64-bit32-bit

How to Compile 32-bit Apps on 64-bit Ubuntu?


I'm trying to compile a 32-bit C application on Ubuntu Server 12.04 LTS 64-bit using gcc 4.8. I'm getting linker error messages about incompatible libraries and skipping -lgcc. What do I need to do to get 32 bit apps compiled and linked?


Solution

  • To get Ubuntu Server 12.04 LTS 64-bit to compile gcc 4.8 32-bit programs, you'll need to do two things.

    1. Make sure all the 32-bit gcc 4.8 development tools are completely installed:

      sudo apt-get install lib32gcc-4.8-dev

    2. Compile programs using the -m32 flag

      gcc pgm.c -m32 -o pgm