Boinst
Boinst

Reputation: 3505

How can one build openssl on ubuntu with a specific version of zlib?

Background

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.

What I've Done

I've built zlib in ~/zlib/zlib-1.2.7, and installed zlib to ~/zlib/lib and ~/zlib/include.

(Note that I've simplified all paths in this post by substituting my working directory for '~')

I've built openssl passing these arguments to ./config

--with-zlib-lib=~/zlib/lib
--with-zlib-include=~/zlib/include

When I build openssl, I can see that the appropriate -I argument is being passed to GCC

./config --prefix=~/openssl --openssldir=openssl/ssl threads zlib-dynamic shared --with-zlib-lib=~/zlib/lib --with-zlib-include=~/zlib/include && make && 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

OpenSSL builds successfully.

The Problem

I check what version of zlib is being linked with the command ldd libssl.so.

ubuntu@lemming012:~/ben/code/optimiser/libs/3rdParty/openssl/lib$ ldd libssl.so
        linux-vdso.so.1 =>  (0x00007fff3e7ff000)
        libcrypto.so.1.0.0 => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0 (0x00007f
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f289bcab000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f289baa6000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f289b88f000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f289c6c7000)

I expect to see ldd reporting my own libz file in the list.

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.

Question

What have I done wrong? How can I get OpenSSL to link to my version of zlib instead of the version installed on the system?

Environment

uBuntu 13.04 x64 compiling with GCC building with Make

Upvotes: 4

Views: 5223

Answers (2)

mangoalex
mangoalex

Reputation: 1

./config --prefix=/data/services/openssl-1.0.2g shared zlib -I/data/services/zlib-1.2.7/include -L/data/services/zlib-1.2.7/lib

Upvotes: -2

Boinst
Boinst

Reputation: 3505

The answer turns out to be, you need to set an rpath with a syntax similar to the following. I do mine in a Makefile, which is the reason for the double '$'.

LDFLAGS    += -Wl,-rpath,'$$ORIGIN/../lib'

Now, I don't necessarily need to do this on the library (openssl) itself. I can do this on the calling executable instead. If the library has no rpath, the rpath on the executable gets used next. In short, I don't need to stress that ldd -r <library> is returning the wrong path, provided that ldd -r <executable> returns the correct path.

I can test by library with the following command:

env LD_LIBRARY_PATH=$PWD ldd -r <library>

And once my executable is compiled, I can verify everything like this:

ldd -r <executable>

Long story short, everything is working just fine, don't get hung up on what ldd -r <library> is returning, just worry about ldd -r <executable>.

Upvotes: 4

Related Questions