From 447618e5fc1d9a541003dc013366d5b207b69b26 Mon Sep 17 00:00:00 2001 From: Daniel Lenski Date: Fri, 21 Jan 2022 08:52:57 -0800 Subject: [PATCH] Change library ordering when testing for library availability with autoconf As discussed in #371, the order in which libraries must be listed on the compiler command-line has changed in recent versions of GCC, in order for linking to succeed. This is because the `--as-needed` option has become enabled by default: https://sigquit.wordpress.com/2011/02/16/why-asneeded-doesnt-work-as-expected-for-your-libraries-on-your-autotools-project A succinct explanation of the required changes in library-ordering from https://wiki.ubuntu.com/NattyNarwhal/ToolchainTransition by way of https://stackoverflow.com/a/69795683: > "The --as-needed option also makes the linker sensitive to the ordering > of libraries on the command-line. You may need to move some libraries > later in the command-line, so they come after other libraries or files > that require symbols from them." [3] It appears that both Debian-based and Fedora-based distributions are moving towards this as the new default behavior: - https://wiki.debian.org/ToolChain/DSOLinking (Debian) - http://fedoraproject.org/wiki/UnderstandingDSOLinkChange (Fedora) Signed-off-by: Daniel Lenski --- configure.ac | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index a0210929..6b7a6555 100644 --- a/configure.ac +++ b/configure.ac @@ -340,7 +340,7 @@ if test "$USE_NLS" = "yes"; then [AC_MSG_RESULT(yes)], [AC_LIB_LINKFLAGS_BODY([intl]) oldLIBS="$LIBS" - LIBS="$LIBS $LIBINTL" + LIBS="$LIBINTL $LIBS" oldCFLAGS="$LIBS" CFLAGS="$CFLAGS $INCINTL" AC_LINK_IFELSE([AC_LANG_PROGRAM([ @@ -406,7 +406,7 @@ if test "$ssl_library" = ""; then elif test "$with_openssl" = "yes" -o "$with_openssl" = ""; then PKG_CHECK_MODULES(OPENSSL, openssl, [AC_SUBST(SSL_PC, [openssl])], [oldLIBS="$LIBS" - LIBS="$LIBS -lssl -lcrypto" + LIBS="-lssl -lcrypto $LIBS" AC_MSG_CHECKING([for OpenSSL without pkg-config]) AC_LINK_IFELSE([AC_LANG_PROGRAM([ #include @@ -471,7 +471,7 @@ case "$ssl_library" in OpenSSL) oldLIBS="${LIBS}" oldCFLAGS="${CFLAGS}" - LIBS="${LIBS} ${OPENSSL_LIBS}" + LIBS="${OPENSSL_LIBS} ${LIBS}" CFLAGS="${CFLAGS} ${OPENSSL_CFLAGS}" # Check for the various known-broken versions of OpenSSL, which includes LibreSSL. @@ -592,7 +592,7 @@ perhaps consider building with GnuTLS instead.)]) GnuTLS) oldlibs="$LIBS" oldcflags="$CFLAGS" - LIBS="$LIBS $GNUTLS_LIBS" + LIBS="$GNUTLS_LIBS $LIBS" CFLAGS="$CFLAGS $GNUTLS_CFLAGS" esp=yes dtls=yes @@ -621,7 +621,7 @@ perhaps consider building with GnuTLS instead.)]) pkcs11_support=GnuTLS AC_SUBST(P11KIT_PC, p11-kit-1)], [:])], []) - LIBS="$oldlibs -ltspi" + LIBS="-ltspi $oldlibs" AC_MSG_CHECKING([for Trousers tss library]) AC_LINK_IFELSE([AC_LANG_PROGRAM([ #include @@ -796,7 +796,7 @@ PKG_CHECK_MODULES([LIBLZ4], [liblz4], [ AC_DEFINE([HAVE_LZ4], [], [LZ4 was found]) lz4_pkg=yes oldLIBS="$LIBS" - LIBS="$LIBS $LIBLZ4_LIBS" + LIBS="$LIBLZ4_LIBS $LIBS" oldCFLAGS="$CFLAGS" CFLAGS="$CFLAGS $LIBLZ4_CFLAGS" AC_MSG_CHECKING([for LZ4_compress_default()]) @@ -863,7 +863,7 @@ AM_CONDITIONAL(BUILTIN_JSON, [test "$json" = "builtin"]) PKG_CHECK_MODULES(ZLIB, zlib, [AC_SUBST(ZLIB_PC, [zlib])], [oldLIBS="$LIBS" - LIBS="$LIBS -lz" + LIBS="-lz $LIBS" AC_MSG_CHECKING([for zlib without pkg-config]) AC_LINK_IFELSE([AC_LANG_PROGRAM([ #include ],[ @@ -893,7 +893,7 @@ dnl libproxy.h in that case. if (test "$libproxy_pkg" = "no"); then AC_MSG_CHECKING([for libproxy]) oldLIBS="$LIBS" - LIBS="$LIBS -lproxy" + LIBS="-lproxy $LIBS" AC_LINK_IFELSE([AC_LANG_PROGRAM([#include ], [(void)px_proxy_factory_new();])], [AC_MSG_RESULT(yes (with libproxy.h)) -- 2.50.1