title: Compiling a 32bit binary that uses ssl on a 64bit Debian wheezy multi-arch host
body: <p>I'm trying to compile a 32 bit binary that uses openssl on a debian wheezy 64 bit host.</p>
  
  <p>I've followed what I believe is the recommended approach of adding the i386 architecture and installing libssl1.0.0:i386.</p>
  
  <p>Just a simple test program fails to link:</p>
  
  <pre><code>#include &lt;openssl/ssl.h&gt;
  int main(void)
  {
      SSL_load_error_strings();
      return 0;
  }
  
  $ gcc -m32 -lssl -o test -Wall test.c
  /usr/bin/ld: cannot find -lssl
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>This same command without the -m32 works fine.</p>
  
  <p>I do have a 32 bit libssl:</p>
  
  <pre><code>$ locate libssl | grep i386
  /usr/lib/i386-linux-gnu/libssl.so.1.0.0
  /usr/lib/i386-linux-gnu/i586/libssl.so.1.0.0
  /usr/lib/i386-linux-gnu/i686/cmov/libssl.so.1.0.0
  </code></pre>
  
  <p>Adding --verbose shows the linker command:</p>
  
  <blockquote>
    <p>/usr/lib/gcc/x86_64-linux-gnu/4.7/collect2 --sysroot=/ --build-id
    --no-add-needed --eh-frame-hdr -m elf_i386 --hash-style=both -dynamic-linker /lib/ld-linux.so.2 -o test /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib32/crt1.o
    /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib32/crti.o
    /usr/lib/gcc/x86_64-linux-gnu/4.7/32/crtbegin.o
    -L/usr/lib/i386-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.7/32 -L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../i386-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib32 -L/lib/i386-linux-gnu -L/lib/../lib32 -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib32 -L/usr/lib/gcc/x86_64-linux-gnu/4.7 -L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../i386-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../.. -L/lib/i386-linux-gnu -L/usr/lib/i386-linux-gnu -lssl /tmp/ccI9DoNH.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.7/32/crtend.o
    /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib32/crtn.o</p>
  </blockquote>
  
  <p>This seems to show that it is searching /usr/lib/i386-linux-gnu/, which is where the libssl.so.1.0.0 is.</p>
  
  <p>The files all seem to be valid according to <code>file</code>:</p>
  
  <pre><code>/usr/lib/i386-linux-gnu/libssl.so.1.0.0:           ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x56052e2cdbad1207690499400909c6c87209735a, stripped
  /usr/lib/i386-linux-gnu/i586/libssl.so.1.0.0:      ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x620bde79657c57fe5ef098d3648ccc2ce4bdb232, stripped
  /usr/lib/i386-linux-gnu/i686/cmov/libssl.so.1.0.0: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, BuildID[sha1]=0x89b973943dfc314c56231d48eddad5fe785f6b12, stripped
  </code></pre>
  
  <p>The other thing I thought of trying was installing libssl-dev:i386, but trying to install this wants to remove the 64bit gcc &amp; g++ compilers and the 64bit libssl-dev, which makes me think it's not the right thing to do (and might stop me building 64 bit binaries):</p>
  
  <pre><code># apt-get install libssl-dev:i386 
  &lt;..&gt;
  The following packages will be REMOVED:
    build-essential cpp g++ g++-multilib gcc gcc-multilib libssl-dev lib tool
  &lt;..&gt;
  </code></pre>
  
  <p>I've tried googling around; I've found other people with the same problem, but no solution.</p>