Compiling and linking a 32 bit application on Debi

2019-04-16 05:39发布

问题:

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.

回答1:

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.


回答2:

The message shows gcc didn't find the 32bit of ncurse library.

A quick solution: looking on my machine (ubuntu 11.10) , I think should be

gcc -m32 -lncurses $^ -o $@ -v

Where the library is actually at /lib32/libncurses.so.5.9.

Generally, try if you encounter a problem.

gcc -m32 -lcurses $^ -o $@ -v

It'll print out a lot of stuff.

Look for parameters looks like -L, and try to find the library file (libfoo.so or libfoo.a) in the directory .



回答3:

You probably need the lib32ncurses5-dev package, or something similar, providing the 32 bits variant development package for ncurses.