[Libguestfs] Build libguestfs error with undefined reference to `guestfs_int_init_libvirt_backend'

Richard W.M. Jones rjones at redhat.com
Thu Oct 15 21:40:52 UTC 2015


The attached patch may be a full fix.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.
http://libguestfs.org/virt-v2v
-------------- next part --------------
>From a1f9e6441dbd20685c36d01d8eea7d6bd82c7679 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones at redhat.com>
Date: Thu, 15 Oct 2015 22:34:13 +0100
Subject: [PATCH] lib: Define HAVE_LIBVIRT_BACKEND where you have too old
 libvirt to run the backend.

In the case where libvirt was installed, but is too old to run the
backend, the libvirt backend would be compiled out but still
referenced by the library.

Fix this by splitting the definition of HAVE_LIBVIRT (libvirt is
installed at all) and HAVE_LIBVIRT_BACKEND (libvirt is new enough to
run the libvirt backend).

Reported by: Efstratios Skleparis.
---
 src/guestfs-internal.h | 20 ++++++++++++++++++--
 src/launch-libvirt.c   | 20 ++------------------
 src/launch.c           |  2 +-
 3 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/src/guestfs-internal.h b/src/guestfs-internal.h
index 34b5f1d..49da6fe 100644
--- a/src/guestfs-internal.h
+++ b/src/guestfs-internal.h
@@ -26,6 +26,22 @@
 
 #include <pcre.h>
 
+/* Minimum required version of libvirt for the libvirt backend.
+ *
+ * This is also checked at runtime because you can dynamically link
+ * with a different version from what you were compiled with.
+ */
+#define MIN_LIBVIRT_MAJOR 0
+#define MIN_LIBVIRT_MINOR 10
+#define MIN_LIBVIRT_MICRO 2 /* XXX patches in > 2 already */
+#define MIN_LIBVIRT_VERSION (MIN_LIBVIRT_MAJOR * 1000000 +	\
+                             MIN_LIBVIRT_MINOR * 1000 +		\
+                             MIN_LIBVIRT_MICRO)
+
+#if defined(HAVE_LIBVIRT) && LIBVIR_VERSION_NUMBER >= MIN_LIBVIRT_VERSION
+#define HAVE_LIBVIRT_BACKEND
+#endif
+
 #ifdef HAVE_LIBVIRT
 #include <libvirt/libvirt.h>
 #endif
@@ -476,7 +492,7 @@ struct guestfs_h
   int ml_debug_calls;        /* Extra debug info on each FUSE call. */
 #endif
 
-#ifdef HAVE_LIBVIRT
+#ifdef HAVE_LIBVIRT_BACKEND
   /* Used by src/libvirt-auth.c. */
 #define NR_CREDENTIAL_TYPES 9
   unsigned int nr_supported_credentials;
@@ -885,7 +901,7 @@ extern bool guestfs_int_discard_possible (guestfs_h *g, struct drive *drv, unsig
 
 /* launch-*.c constructors */
 void guestfs_int_init_direct_backend (void) __attribute__((constructor));
-#ifdef HAVE_LIBVIRT
+#ifdef HAVE_LIBVIRT_BACKEND
 void guestfs_int_init_libvirt_backend (void) __attribute__((constructor));
 #endif
 void guestfs_int_init_uml_backend (void) __attribute__((constructor));
diff --git a/src/launch-libvirt.c b/src/launch-libvirt.c
index 1a690e8..1649884 100644
--- a/src/launch-libvirt.c
+++ b/src/launch-libvirt.c
@@ -61,23 +61,7 @@
 #endif
 /* End of fixes for Mac OS X */
 
-/* Check minimum required version of libvirt.  The libvirt backend
- * is new and not the default, so we can get away with forcing
- * people who want to try it to have a reasonably new version of
- * libvirt, so we don't have to work around any bugs in libvirt.
- *
- * This is also checked at runtime because you can dynamically link
- * with a different version from what you were compiled with.
- */
-#define MIN_LIBVIRT_MAJOR 0
-#define MIN_LIBVIRT_MINOR 10
-#define MIN_LIBVIRT_MICRO 2 /* XXX patches in > 2 already */
-#define MIN_LIBVIRT_VERSION (MIN_LIBVIRT_MAJOR * 1000000 +	\
-                             MIN_LIBVIRT_MINOR * 1000 +		\
-                             MIN_LIBVIRT_MICRO)
-
-#if defined(HAVE_LIBVIRT) &&			\
-  LIBVIR_VERSION_NUMBER >= MIN_LIBVIRT_VERSION
+#ifdef HAVE_LIBVIRT_BACKEND
 
 #ifndef HAVE_XMLBUFFERDETACH
 /* Added in libxml2 2.8.0.  This is mostly a copy of the function from
@@ -2308,4 +2292,4 @@ guestfs_int_init_libvirt_backend (void)
   guestfs_int_register_backend ("libvirt", &backend_libvirt_ops);
 }
 
-#endif
+#endif /* HAVE_LIBVIRT_BACKEND */
diff --git a/src/launch.c b/src/launch.c
index ddd7091..23e5414 100644
--- a/src/launch.c
+++ b/src/launch.c
@@ -520,7 +520,7 @@ guestfs_int_set_backend (guestfs_h *g, const char *method)
 void *
 guestfs_int_force_load_backends[] = {
   guestfs_int_init_direct_backend,
-#ifdef HAVE_LIBVIRT
+#ifdef HAVE_LIBVIRT_BACKEND
   guestfs_int_init_libvirt_backend,
 #endif
   guestfs_int_init_uml_backend,
-- 
2.5.0



More information about the Libguestfs mailing list