[libvirt] [PATCH] Put libraries in $LIBS, not $LDFLAGS, during configure tests.

If libraries go in $LDFLAGS while AC_CHECK_LIBbing, they'll end up in front of the object file name, which rarely works well. They belong in $LIBS. --- configure.in | 25 ++++++++++++------------- 1 files changed, 12 insertions(+), 13 deletions(-) diff --git a/configure.in b/configure.in index f735bba..5308364 100644 --- a/configure.in +++ b/configure.in @@ -542,14 +542,14 @@ AC_SUBST([LIBXML_LIBS]) dnl xmlURI structure has query_raw? old_cflags="$CFLAGS" -old_ldflags="$LDFLAGS" +old_libs="$LIBS" CFLAGS="$CFLAGS $LIBXML_CFLAGS" -LDFLAGS="$LDFLAGS $LIBXML_LIBS" +LIBS="$LIBS $LIBXML_LIBS" AC_CHECK_MEMBER([struct _xmlURI.query_raw], [AC_DEFINE([HAVE_XMLURI_QUERY_RAW], [], [Have query_raw field in libxml2 xmlURI structure])],, [#include <libxml/uri.h>]) CFLAGS="$old_cflags" -LDFLAGS="$old_ldflags" +LIBS="$old_libs" dnl GnuTLS library GNUTLS_CFLAGS= @@ -579,15 +579,15 @@ dnl Old versions of GnuTLS uses types like 'gnutls_session' instead dnl of 'gnutls_session_t'. Try to detect this type if defined so dnl that we can offer backwards compatibility. old_cflags="$CFLAGS" -old_ldflags="$LDFLAGS" +old_libs="$LIBS" CFLAGS="$CFLAGS $GNUTLS_CFLAGS" -LDFLAGS="$LDFLAGS $GNUTLS_LIBS" +LIBS="$LIBS $GNUTLS_LIBS" AC_CHECK_TYPE([gnutls_session], AC_DEFINE([GNUTLS_1_0_COMPAT],[], [enable GnuTLS 1.0 compatibility macros]),, [#include <gnutls/gnutls.h>]) CFLAGS="$old_cflags" -LDFLAGS="$old_ldflags" +LIBS="$old_libs" dnl Cyrus SASL @@ -685,12 +685,12 @@ if test "x$with_polkit" = "xyes" -o "x$with_polkit" = "xcheck"; then [use PolicyKit for UNIX socket access checks]) old_CFLAGS=$CFLAGS - old_LDFLAGS=$LDFLAGS + old_LIBS=$LIBS CFLAGS="$CFLAGS $POLKIT_CFLAGS" - LDFLAGS="$LDFLAGS $POLKIT_LIBS" + LIBS="$LIBS $POLKIT_LIBS" AC_CHECK_FUNCS([polkit_context_is_caller_authorized]) CFLAGS="$old_CFLAGS" - LDFLAGS="$old_LDFLAGS" + LIBS="$old_LIBS" AC_PATH_PROG([POLKIT_AUTH], [polkit-auth]) if test "x$POLKIT_AUTH" != "x"; then @@ -1682,20 +1682,19 @@ if test "x$with_hal" = "xyes" -o "x$with_hal" = "xcheck"; then [use HAL for host device enumeration]) old_CFLAGS=$CFLAGS - old_LDFLAGS=$LDFLAGS + old_LIBS=$LIBS CFLAGS="$CFLAGS $HAL_CFLAGS" - LDFLAGS="$LDFLAGS $HAL_LIBS" + LIBS="$LIBS $HAL_LIBS" AC_CHECK_FUNCS([libhal_get_all_devices],,[with_hal=no]) AC_CHECK_FUNCS([dbus_watch_get_unix_fd]) CFLAGS="$old_CFLAGS" - LDFLAGS="$old_LDFLAGS" + LIBS="$old_LIBS" fi fi AM_CONDITIONAL([HAVE_HAL], [test "x$with_hal" = "xyes"]) AC_SUBST([HAL_CFLAGS]) AC_SUBST([HAL_LIBS]) - dnl udev/libpciaccess library check for alternate host device enumeration UDEV_CFLAGS= UDEV_LIBS= -- 1.6.5.3.100.g75959

On Mon, Nov 23, 2009 at 09:28:24PM +0000, Nix wrote:
If libraries go in $LDFLAGS while AC_CHECK_LIBbing, they'll end up in front of the object file name, which rarely works well. They belong in $LIBS.
What platforms / scenarios show this problem ? Empirically it has been working fine on our commonly tested platforms, so it'll be important to know where to look/test for this problem.
--- configure.in | 25 ++++++++++++------------- 1 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/configure.in b/configure.in index f735bba..5308364 100644 --- a/configure.in +++ b/configure.in @@ -542,14 +542,14 @@ AC_SUBST([LIBXML_LIBS])
dnl xmlURI structure has query_raw? old_cflags="$CFLAGS" -old_ldflags="$LDFLAGS" +old_libs="$LIBS" CFLAGS="$CFLAGS $LIBXML_CFLAGS" -LDFLAGS="$LDFLAGS $LIBXML_LIBS" +LIBS="$LIBS $LIBXML_LIBS" AC_CHECK_MEMBER([struct _xmlURI.query_raw], [AC_DEFINE([HAVE_XMLURI_QUERY_RAW], [], [Have query_raw field in libxml2 xmlURI structure])],, [#include <libxml/uri.h>]) CFLAGS="$old_cflags" -LDFLAGS="$old_ldflags" +LIBS="$old_libs"
dnl GnuTLS library GNUTLS_CFLAGS= @@ -579,15 +579,15 @@ dnl Old versions of GnuTLS uses types like 'gnutls_session' instead dnl of 'gnutls_session_t'. Try to detect this type if defined so dnl that we can offer backwards compatibility. old_cflags="$CFLAGS" -old_ldflags="$LDFLAGS" +old_libs="$LIBS" CFLAGS="$CFLAGS $GNUTLS_CFLAGS" -LDFLAGS="$LDFLAGS $GNUTLS_LIBS" +LIBS="$LIBS $GNUTLS_LIBS" AC_CHECK_TYPE([gnutls_session], AC_DEFINE([GNUTLS_1_0_COMPAT],[], [enable GnuTLS 1.0 compatibility macros]),, [#include <gnutls/gnutls.h>]) CFLAGS="$old_cflags" -LDFLAGS="$old_ldflags" +LIBS="$old_libs"
dnl Cyrus SASL @@ -685,12 +685,12 @@ if test "x$with_polkit" = "xyes" -o "x$with_polkit" = "xcheck"; then [use PolicyKit for UNIX socket access checks])
old_CFLAGS=$CFLAGS - old_LDFLAGS=$LDFLAGS + old_LIBS=$LIBS CFLAGS="$CFLAGS $POLKIT_CFLAGS" - LDFLAGS="$LDFLAGS $POLKIT_LIBS" + LIBS="$LIBS $POLKIT_LIBS" AC_CHECK_FUNCS([polkit_context_is_caller_authorized]) CFLAGS="$old_CFLAGS" - LDFLAGS="$old_LDFLAGS" + LIBS="$old_LIBS"
AC_PATH_PROG([POLKIT_AUTH], [polkit-auth]) if test "x$POLKIT_AUTH" != "x"; then @@ -1682,20 +1682,19 @@ if test "x$with_hal" = "xyes" -o "x$with_hal" = "xcheck"; then [use HAL for host device enumeration])
old_CFLAGS=$CFLAGS - old_LDFLAGS=$LDFLAGS + old_LIBS=$LIBS CFLAGS="$CFLAGS $HAL_CFLAGS" - LDFLAGS="$LDFLAGS $HAL_LIBS" + LIBS="$LIBS $HAL_LIBS" AC_CHECK_FUNCS([libhal_get_all_devices],,[with_hal=no]) AC_CHECK_FUNCS([dbus_watch_get_unix_fd]) CFLAGS="$old_CFLAGS" - LDFLAGS="$old_LDFLAGS" + LIBS="$old_LIBS" fi fi AM_CONDITIONAL([HAVE_HAL], [test "x$with_hal" = "xyes"]) AC_SUBST([HAL_CFLAGS]) AC_SUBST([HAL_LIBS])
- dnl udev/libpciaccess library check for alternate host device enumeration UDEV_CFLAGS= UDEV_LIBS=
ACK Daniel -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|

On 25 Nov 2009, Daniel P. Berrange spake thusly:
On Mon, Nov 23, 2009 at 09:28:24PM +0000, Nix wrote:
If libraries go in $LDFLAGS while AC_CHECK_LIBbing, they'll end up in front of the object file name, which rarely works well. They belong in $LIBS.
What platforms / scenarios show this problem ? Empirically it has been working fine on our commonly tested platforms, so it'll be important to know where to look/test for this problem.
Autoconf has always sorted $LDFLAGS before object files. When -Wl,--as-needed is turned on by default (as a number of distros do), such libraries are silently dropped because nothing needs symbols from them at that point in the link, just as if they were static libraries. Without -Wl,--as-needed, every single library named in the link is added to DT_NEEDED, so this works. Nonetheless, it is plainly obvious to any Unix hand that cc -L/usr/lib -lfoo -o test thing-that-uses-foo.o is less likely to work than cc -L/usr/lib -o test thing-that-uses-foo.o -lfoo and if you put libraries in LDFLAGS, the former's often what you get. It'll probably fail for you, too, if HAL (say) is statically linked, because the -Wl,--as-needed behaviour for shared libraries is exactly how static libraries have always worked. The GNU Autoconf manual has long stated -- Variable: LDFLAGS [...] Don't use this variable to pass library names (`-l') to the linker; use `LIBS' instead. (I'm surprised that no Gentooers, for instance, have reported this already. A *lot* of distros turn on -Wl,--as-needed by default these days, often by modifying the built-in GCC specs and providing a fallback specs file that specifies -Wl,--no-as-needed for those very rare things, such as glibc's testsuite, that actually *require* linkage with shared libraries from which no symbols are required.)
participants (2)
-
Daniel P. Berrange
-
Nix