Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Static linking with zlib

283 views
Skip to first unread message

Jeff Nathan

unread,
Apr 16, 2010, 5:24:20 PM4/16/10
to
I'm experiencing what I would have thought would be a common
occurrence but doesn't appear to be so. So, I'm writing this message
in the hope that someone can at least clarify the issue if not work
towards a solution. All my compilation is at present being tested on
a FreeBSD 7.1 system on an amd64 architecture.

First, I build and install a static zlib 1.2.3 into /my/special/path

Next, I build and install a static openssl 1.0.0 into
/my/special/path, configured as follows:
./config zlib no-shared no-zlib-dynamic --prefix=/my/special/path
--with-zlib-include=/my/special/path/include
--with-zlib-lib=/my/special/path/lib -fPIC

Last, I build third-party libraries and applications such as curl
which link against openssl. Unless I pass -lz in the LIBS environment
variable when calling the GNU autotools configure script for curl, the
configure script fails when checking for SSL_connect in libssl.a.
Examining the output of the configure tests for curl, it becomes clear
that there are a number of undefined symbols from zlib in libcrypto.a:

(from curl's config.log)
configure:18966: checking for SSL_connect in -lssl
configure:18988: gcc -o conftest -fPIC -isystem
/my/special/path/include -g0 -O2 -Wno-system-headers
-I/my/special/path/include -I/my/special/path/include/openssl
-L/my/special/path/lib -L/my/special/path/lib conftest.c -lssl
-lcrypto >&5
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x6f): In function
`bio_zlib_free':
: undefined reference to `inflateEnd'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x8d): In function
`bio_zlib_free':
: undefined reference to `deflateEnd'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x394): In function
`bio_zlib_ctrl':
: undefined reference to `deflate'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x46d): In function
`bio_zlib_ctrl':
: undefined reference to `zError'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x51a): In function
`bio_zlib_read':
: undefined reference to `inflate'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x596): In function
`bio_zlib_read':
: undefined reference to `zError'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x5f4): In function
`bio_zlib_read':
: undefined reference to `inflateInit_'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x6e7): In function
`bio_zlib_write':
: undefined reference to `deflate'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x76e): In function
`bio_zlib_write':
: undefined reference to `zError'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x807): In function
`bio_zlib_write':
: undefined reference to `deflateInit_'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0x972): In function
`zlib_stateful_expand_block':
: undefined reference to `inflate'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0xa19): In function
`zlib_stateful_compress_block':
: undefined reference to `deflate'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0xa5f): In function
`zlib_stateful_finish':
: undefined reference to `inflateEnd'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0xa68): In function
`zlib_stateful_finish':
: undefined reference to `deflateEnd'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0xb22): In function
`zlib_stateful_init':
: undefined reference to `inflateInit_'
/my/special/path/lib/libcrypto.a(c_zlib.o)(.text+0xba8): In function
`zlib_stateful_init':
: undefined reference to `deflateInit_'

Adding -lz resolves these symbols which leads to my question: why
aren't the symbols from zlib resolved during the compilation and
linking such that an application not directly calling out to zlib need
not link against it if it only wishes to use openssl?

My thanks in advance for any help that can be offered on the subject.

Regards,

-Jeff
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List opens...@openssl.org
Automated List Manager majo...@openssl.org

Phillip Hellewell

unread,
Apr 17, 2010, 12:01:47 AM4/17/10
to
On Fri, Apr 16, 2010 at 3:24 PM, Jeff Nathan <je...@snort.org> wrote:
Adding -lz resolves these symbols which leads to my question: why
aren't the symbols from zlib resolved during the compilation and
linking such that an application not directly calling out to zlib need
not link against it if it only wishes to use openssl?

With static libraries everything needs to be linked into the executable.  Perhaps you thought when building openssl that the functions in libz.a would get embedded inside of libcrypto.a, but they don't.

However, if you really did want to create a static library that combines everything from libz.a and libcrypto.a, you could do that easily enough using the "ar" command.

Phillip

Ori Kovacsi-Katz

unread,
Dec 21, 2022, 7:37:06 AM12/21/22
to
I have same difficulty now attempting build boost::beast with statically linked zlib and openssl, need help to implement your tip with AR?
Ori Kovacsi Katz
0 new messages