title: Building a 32-bit app in 64-bit Ubuntu
body: <p>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 <strong>CFLAGS=-m32</strong> and the <strong>LDFLAGS=-L/usr/lib32</strong> 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:</p>
  
  <pre><code>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
  ...
  </code></pre>
  
  <p>I have installed <strong>ia32-libs</strong> and <strong>mutilib support</strong>. I think I just need to force the linker to generate a i386 output. I tried to put two <strong>ld</strong> flags in my gcc command as shown above: <strong>-melf_i386</strong> and <strong>-oformat elf32-i386</strong>. But what happens is that gcc doesn't search for the 32 bit library in <strong>/usr/lib32</strong> anymore. I wonder if I need to put those flags in some fixed order? </p>
  
  <p>Thanks for any idea and help!</p>
  
  <p><strong>EDIT</strong>: 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: </p>
  
  <pre><code>/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
  </code></pre>
  
  <p>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.</p>