title: How can one build openssl on ubuntu with a specific version of zlib?
body: <p><strong>Background</strong></p>
  
  <p>I'd like to build OpenSSL against a specific version of zlib so that all of my code is built by me. I do this for many of the libraries I use so that I don't get different behaviour on different versions of the operating system. I understand that this isn't strictly necessary, but I wanna.</p>
  
  <p><strong>What I've Done</strong></p>
  
  <p>I've built zlib in ~/zlib/zlib-1.2.7, and installed zlib to ~/zlib/lib and ~/zlib/include.</p>
  
  <p><em>(Note that I've simplified all paths in this post by substituting my working directory for '~')</em></p>
  
  <p>I've built openssl passing these arguments to ./config</p>
  
  <pre><code>--with-zlib-lib=~/zlib/lib
  --with-zlib-include=~/zlib/include
  </code></pre>
  
  <p>When I build openssl, I can see that the appropriate -I argument is being passed to GCC</p>
  
  <pre><code>./config --prefix=~/openssl --openssldir=openssl/ssl threads zlib-dynamic shared --with-zlib-lib=~/zlib/lib --with-zlib-include=~/zlib/include &amp;&amp; make &amp;&amp; make install
  . . .
  ...many lines of output...
  . . .
  gcc -I.. -I../.. -I../modes -I../asn1 -I../evp -I../../include -I/home/ubuntu/zlib/include -fPIC -DOPENSSL_PIC -DZLIB_SHARED -DZLIB -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -Wa,--noexecstack -m64 -DL_ENDIAN -DTERMIO -O3 -Wall -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHASH_ASM   -c -o cm_pmeth.o cm_pmeth.c
  </code></pre>
  
  <p>OpenSSL builds successfully.</p>
  
  <p><strong>The Problem</strong></p>
  
  <p>I check what version of zlib is being linked with the command <code>ldd libssl.so</code>.</p>
  
  <pre><code>ubuntu@lemming012:~/ben/code/optimiser/libs/3rdParty/openssl/lib$ ldd libssl.so
          linux-vdso.so.1 =&gt;  (0x00007fff3e7ff000)
          libcrypto.so.1.0.0 =&gt; /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f
          libc.so.6 =&gt; /lib/x86_64-linux-gnu/libc.so.6 (0x00007f289bcab000)
          libdl.so.2 =&gt; /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f289baa6000)
          libz.so.1 =&gt; /lib/x86_64-linux-gnu/libz.so.1 (0x00007f289b88f000)
          /lib64/ld-linux-x86-64.so.2 (0x00007f289c6c7000)
  </code></pre>
  
  <p>I expect to see ldd reporting my own libz file in the list.</p>
  
  <p>Instead, ldd reports that libssl is linked to my system installed version of libz. The results are identical if I copy my own version libz.so.1 into the libssl 'lib' directory before running ldd in that same directory.</p>
  
  <p><strong>Question</strong></p>
  
  <p>What have I done wrong? How can I get OpenSSL to link to <em>my</em> version of zlib instead of the version installed on the system?</p>
  
  <p><strong>Environment</strong></p>
  
  <p>uBuntu 13.04 x64 
  compiling with GCC
  building with Make</p>