title: How to compile applications for the i386 arch on a x86_64 host
body: <p>Years and years after resisting a switch to the x86_64 platform, finally I made the switch. Primarily because I wanted to play around with docker (FTW: <a href="http://docker.io" rel="nofollow">http://docker.io</a>).</p>
  
  <p>In my line of duty I generally have to build applications for the 32 bit platform. And thus came the need to compile applications for i386 on the x86_64 host.</p>
  
  <p>I am using ubuntu 13.04. I looked around a lot to figure this out before posting this question.</p>
  
  <p>So here's what I gathered:
  1. Need to have gcc-multilib installed (apt-get install gcc-multilib)
  2. Need to have ia32-libs installed (apt-get install ia32-libs)
  3. We need to specify -m32 switch to GCC</p>
  
  <p>As a result, I can compile applications for i386.
  eg.</p>
  
  <pre><code>   $ uname -m
     x86_64
     $
     $ echo -e "#include &lt;stdio.h&gt;\nint main () {return 0;}" &gt; dummy.c
     $ gcc -m32 dummy.c -o dummy
     $ file dummy
     dummy: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xafbf2b3adc5f44a8b5c1e8bcd6de5701ff792abd, not stripped
  </code></pre>
  
  <p>Now here's the problem. When I try to link against the zlib library.</p>
  
  <pre><code>   $ apt-get install zlib1g-dev
     $ apt-get install zlib1g:i386 # the i386 version of zlib 
     $ gcc -m32 dummy.c -o dummy -lz
     /usr/bin/ld: cannot find -lz
     collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>I am not able to figure out this issue. How do I resolve it. As per my currently understanding I have installed all the required packages...</p>
  
  <p>I have looked at solving this issues using 
  a. Linux containers / docker.
  b. Ubuntu 13.04 i386 jailed root.</p>
  
  <p>Both of the above methods work. But there are quite a few hoops to get by before getting to the point of being able to build. </p>
  
  <p>But what could be better than just getting the i386 applications to compile on the x86_64 host.</p>
  
  <p>Any help is greatly appreciated.</p>
  
  <p>Thanks and Regards
  ~Sameer</p>