Skip to content
Advertisement

Compiling and linking a 32 bit application on Debian 64 bit

I am currently trying to compile and link a 32 bit application on my Debian 64 bit, but it fails at link time.

The command I’m using (in my Makefile) to compile is:

gcc -Os -m32 -Wall -g -c $< -o $@

This seems to work.

Then I link with the following command:

gcc -m32 -lcurses $^ -o $@

This fails and gives the following errors:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libcurses.so when searching for -lcurses
/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.4.5/../../../libcurses.a when searching for -lcurses
/usr/bin/ld: skipping incompatible /usr/lib/libcurses.so when searching for -lcurses
/usr/bin/ld: skipping incompatible /usr/lib/libcurses.a when searching for -lcurses
/usr/bin/ld: cannot find -lcurses
collect2: ld returned 1 exit status    

What I’ve tried so far (usual solutions that I found elsewhere on the web) is:

  • installing gcc-multilib
  • installing lib32ncurses5 and lib32ncurses6dev
  • adding the option -L/usr/lib32 to the link command

Sadly, none of these has worked so far. I am running out of ideas. My last resort would be using a 32 bit system, but I’d like to avoid that if possible.

Advertisement

Answer

There are two problems:

  1. Your link command is incorrect: the order of libraries on the link line matters. The command should be: gcc -m32 $^ -o $@ -lcurses
  2. Since you want to link against ncurses, make the last argument -lncurses.
Advertisement