Skip to content
Snippets Groups Projects
Commit 2cdfaf3b authored by Alexander Turenko's avatar Alexander Turenko Committed by Kirill Yukhin
Browse files

build: fix linking with static openssl library

System-wide dynamic libraries usually (always?) have NEEDED and RUNPATH
tags in a dynamic section (as `readelf -d /usr/lib/lib<...>.so` shows),
so when we link, say, with libssl.so, which depends on libz.so, a linker
does not complain against unresolved symbols that can be found in Z
library (if it is installed within a system).

Things are different when we linking with a static library. Say, when we
linking with libssl.a, which contains an unresolved symbol from Z
library, a linker reports an error. It is not possible to store an
information where to find unresolved symbols (NEEDED / RUNPATH) in a
static library (AFAIK).

We depend on three libraries that are depend on Z library: libcurl,
libssl and libcrypto (two latter are part of OpenSSL). When one of those
libraries is linked statically we should link with libz.so or libz.a
(depending on BUILD_STATIC flag). The patch doing exactly this.

The patch changes OPENSSL_LIBRARIES variable to fix the issue with
static linking of OpenSSL libraries. It also changes CURL_LIBRARIES in
the same way, however this does not alter any visible behaviour, because
OPENSSL_LIBRARIES is added to CURL_LIBRARIES. The latter change was made
to unify the way to choose libraries to link with: it is pure
refactoring part.

Fixes #4437.
parent 9ee5cf82
No related branches found
No related tags found
No related merge requests found
......@@ -324,10 +324,14 @@ endif()
#
# OpenSSL can require Z library (depending on build time options), so we add
# it to libraries list in case of static build.
# it to libraries list in case of static openssl linking.
#
if(BUILD_STATIC)
find_library(Z_LIBRARY libz.a)
if(OPENSSL_USE_STATIC_LIBS)
if(BUILD_STATIC)
find_library(Z_LIBRARY libz.a)
else()
find_library(Z_LIBRARY z)
endif()
set(OPENSSL_LIBRARIES ${OPENSSL_LIBRARIES} ${Z_LIBRARY})
endif()
......
......@@ -18,9 +18,11 @@
if(BUILD_STATIC)
set(CURL_LIB_NAME libcurl.a)
set(Z_LIB_NAME libz.a)
set(NGHTTP2_LIB_NAME libnghttp2.a)
else()
set(CURL_LIB_NAME curl)
set(Z_LIB_NAME z)
set(NGHTTP2_LIB_NAME nghttp2)
endif()
......@@ -30,6 +32,7 @@ set(DL_LIB_NAME dl)
# Curl may be linked with optional or target-dependent libraries,
# search for them and add to dependicies if found.
find_library(Z_LIBRARY NAMES ${Z_LIB_NAME})
find_library(NGHTTP2_LIBRARY NAMES ${NGHTTP2_LIB_NAME})
find_library(PTHREAD_LIBRARY NAMES ${PTHREAD_LIB_NAME})
find_library(DL_LIBRARY NAMES ${DL_LIB_NAME})
......@@ -88,6 +91,9 @@ if(CURL_FOUND)
set(CURL_LIBRARIES ${CURL_LIBRARIES} ${OPENSSL_LIBRARIES})
if(BUILD_STATIC)
# In case of a static build we have to add curl dependencies.
if(NOT "${Z_LIBRARY}" STREQUAL "Z_LIBRARY-NOTFOUND")
set(CURL_LIBRARIES ${CURL_LIBRARIES} ${Z_LIBRARY})
endif()
if(NOT "${NGHTTP2_LIBRARY}" STREQUAL "NGHTTP2_LIBRARY-NOTFOUND")
set(CURL_LIBRARIES ${CURL_LIBRARIES} ${NGHTTP2_LIBRARY})
endif()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment