How to compile 32-bit applications on 64-bit Ubuntu?

I am trying to compile a 32-bit C application on Ubuntu Server 12.04 LTS 64-bit using gcc 4.8. I get linker error messages about incompatible libraries and skipping -lgcc . What do I need to do to compile and link 32-bit applications?

+18
64bit ubuntu 32-bit
Mar 12 '14 at 2:58
source share
3 answers

In order to get Ubuntu Server 12.04 LTS 64-bit to compile 32-bit gcc 4.8 programs, you need to do two things.

  • Ensure that all 32-bit gcc 4.8 development tools are fully installed:

    sudo apt-get install lib32gcc-4.8-dev

  • Compile programs using the -m32 flag

    gcc pgm.c -m32 -o pgm

+7
Mar 12 '14 at 2:58
source share

Ubuntu 14.04

 sudo apt-get install gcc-multilib 

For some reason, on Ubuntu 17.04, I also needed to install a version-related version:

 sudo apt-get install gcc-6-multilib 

Then minimal world hi:

 #include <stdio.h> int main() { puts("Hello world!"); return 0; } 

compiles without warning:

 gcc -m32 -pedantic-errors -std=c89 -Wall hello_world.c 

and

 ./a.out 

gives: Hello world! as expected, and:

 file a.out 

He speaks:

 a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=87c87a83878ce7e7d23b6236e4286bf1daf59033, not stripped 

and

 qemu-i386 a.out 

also gives: Hello world! but crash for x86_64 executable

In addition, I have:

So I think this works :-)

See also: Cannot find crtn.o by associating 32-bit code with a 64-bit system

+31
Apr 24 '15 at 13:34
source share

Multiarch support is supported by adding architecture information to the names of the packages you want to install (instead of installing these packages using alternative names that may or may not be available).

See this answer for more information on a (modern) multi-archive installation.

In your case, you would be better off installing 32-bit gcc and libc:

 sudo apt-get install libc6-dev:i386 gcc:i386 

It will install the 32-bit libc and gcc developments and all the dependent packages (all 32-bit versions) next to your 64-bit installation, without breaking it.

+6
Dec 16 '14 at 13:06
source share



All Articles