Building a 32-bit app in 64-bit Ubuntu

LDFLAGS should include -m32 as well. Following should work:

export LDFLAGS='-m32 -L/usr/lib32'

In fact, you can drop -L/usr/lib32 part, since this is a default directory for 32bit libs, and your system is aware about that.

Basically, the simplest way to build 32bit application on 64bit machine is:

export CFLAGS='-m32'
export CXXFLAGS='-m32'
export LDFLAGS='-m32'
make

..or feed those variables to configure script if you're using autotools.

UPDATE:

Seems like you are not really familiar about the differences in linking with static and dynamic libraries. I'll try to be as minimal as possible:

  • Both static and dynamic development libraries have the same file extension .a
  • If you have installed both static and dynamic versions of the same library, one of them might have additional postfix, like libname.a for dynamic and libname_s.a for static version.
  • Sure, static and dynamic library versions differs in size. Static version is heavier.
  • If you link with static library - your application has no dependencies. If you link with dynamic library, it will rely on .so runtime library that should be present in your system.

Please note, we are not talking about advanced tricks here, like explicit loading of DSO's using the dlopen()/dlsym() API.


I was getting errors such as:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.8/libstdc++.so when searching for -lstdc++

This fixed it for me:

sudo apt-get install g++-multilib

if you are using a gcc package other than the default one (e.g. gcc-7), then you'll need to install the package for that specific version:

sudo apt-get install g++-7-multilib

Tags:

64 Bit

Gcc