Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Building a 32-bit app in 64-bit Ubuntu

After hours of googling, I decide to give up and ask you experts. I am trying to build a 32-bit application (xgap if anyone interested) in my 64 Ubuntu 11.10. I added the CFLAGS=-m32 and the LDFLAGS=-L/usr/lib32 in the makefile. The objects are built into 32 bit fine. The last step is to link all the objects and libraries for X windows into this executable---xgap. Somehow it keeps giving me this error:

gcc -o xgap xcmds.o utils.o gapgraph.o gaptext.o pty.o popdial.o xgap.o selfile.o   -L/usr/lib32 -lXaw -lXmu -lXt -lXext -lX11  -lSM -lICE

/usr/bin/ld: skipping incompatible /usr/lib32/libXmu.so when searching for -lXmu
...

/usr/bin/ld: i386 architecture of input file `xcmds.o' is incompatible with i386:x86-64 output
...

I have installed ia32-libs and mutilib support. I think I just need to force the linker to generate a i386 output. I tried to put two ld flags in my gcc command as shown above: -melf_i386 and -oformat elf32-i386. But what happens is that gcc doesn't search for the 32 bit library in /usr/lib32 anymore. I wonder if I need to put those flags in some fixed order?

Thanks for any idea and help!

EDIT: when I add the -m32 flag in my last gcc command (the linking stage I believe), even if I have the -L/usr/lib32 flag in place, gcc doesn't search in /usr/lib32 anymore ( really weird...) and generates the following error:

/usr/bin/ld: skipping incompatible /usr/lib/gcc/x86_64-linux-gnu/4.6.1/../../../libXaw.so when searching for -lXaw
/usr/bin/ld: skipping incompatible /usr/lib/libXaw.so when searching for -lXaw
/usr/bin/ld: cannot find -lXaw
collect2: ld returned 1 exit status

Any one has any idea why this happens? I am using the auto tool to configure and make. I am really good at modifying those script files.

like image 992
Rich Avatar asked Dec 07 '11 19:12

Rich


People also ask

Can you run 32-bit on 64-bit Ubuntu?

To install 32-bit libraries on Ubuntu 13.04 (64-bit) or later, open Terminal and type: sudo apt-get install lib32z1 (you will need to enter your password). Then just for good measure, let's make sure your Ubuntu is up to date. Type sudo apt-get update and lastly, restart your computer.

Does Ubuntu 20.04 support 32-bit applications?

No, Ubuntu 20.04 does not support 32-bit. You will need a 64-bit computer to run Ubuntu 20.04.

Is gcc 32 or 64-bit?

Mostly compiler(gcc or clang) of C and C++, nowadays come with default 64-bit version.

Does Ubuntu support 32bit?

We recommend publishing applications as snaps, which can leverage the “core18” runtime which supports 32-bit via the existing Ubuntu 18.04 archive. Q. I have 32bit 16.04 LTS / 18.04 LTS installed, what are my upgrade options? 18.04 LTS has Standard Security support until 2023.


2 Answers

You need to use link with -m32 as well.

gcc -m32 -o xgap xcmds.o utils.o gapgraph.o gaptext.o pty.o popdial.o xgap.o selfile.o   -L/usr/lib32 -lXaw -lXmu -lXt -lXext -lX11  -lSM -lICE

All things considered, I think you should be able to drop the -L/usr/lib32 when using -m32.

like image 181
rubenvb Avatar answered Oct 18 '22 19:10

rubenvb


I solved the problem. I think that gcc was expecting a static library archive. I used the getlibs script from http://ubuntuforums.org/showthread.php?t=474790 to download all the .a archives needed for linking. Then gcc worked. I think gcc did search in /usr/lib32 directory but didn't find the .a archives so went on to search in the standard directory which is /usr/lib, where it finds the incompatible *.so files.

But then the question is: the *.so files in /usr/lib32/ from package ia32-libs doesn't really have the libraries needed for linking? What are those files in /usr/lib32/ used for?

like image 1
Rich Avatar answered Oct 18 '22 19:10

Rich