Use the __declspec(dllexport/dllimport) stuff to export the symbol,
otherwise accessing virConnectAuthPtrDefault triggers a segfault.
---
configure.ac | 11 +++++++++++
docs/apibuild.py | 1 +
include/libvirt/libvirt.h.in | 16 +++++++++++++++-
src/Makefile.am | 4 +++-
4 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/configure.ac b/configure.ac
index 1a3c788..bcf1d5a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1732,6 +1732,7 @@ CYGWIN_EXTRA_LDFLAGS=
CYGWIN_EXTRA_LIBADD=
CYGWIN_EXTRA_PYTHON_LIBADD=
MINGW_EXTRA_LDFLAGS=
+WIN32_EXTRA_CFLAGS=
case "$host" in
*-*-cygwin*)
CYGWIN_EXTRA_LDFLAGS="-no-undefined"
@@ -1744,10 +1745,20 @@ case "$host" in
MINGW_EXTRA_LDFLAGS="-no-undefined"
;;
esac
+case "$host" in
+ *-*-mingw* | *-*-cygwin* | *-*-msvc* )
+ # If the host is Windows, and shared libraries are disabled, we
+ # need to add -DLIBVIRT_STATIC to the CFLAGS for proper linking
+ if test "x$enable_shared" = "xno"; then
+ WIN32_EXTRA_CFLAGS="-DLIBVIRT_STATIC"
+ fi
+ ;;
+esac
AC_SUBST([CYGWIN_EXTRA_LDFLAGS])
AC_SUBST([CYGWIN_EXTRA_LIBADD])
AC_SUBST([CYGWIN_EXTRA_PYTHON_LIBADD])
AC_SUBST([MINGW_EXTRA_LDFLAGS])
+AC_SUBST([WIN32_EXTRA_CFLAGS])
dnl Look for windres to build a Windows icon resource.
AC_CHECK_TOOL([WINDRES], [windres], [no])
diff --git a/docs/apibuild.py b/docs/apibuild.py
index 0ab5db2..2dda4df 100755
--- a/docs/apibuild.py
+++ b/docs/apibuild.py
@@ -28,6 +28,7 @@ ignored_words = {
"ATTRIBUTE_UNUSED": (0, "macro keyword"),
"ATTRIBUTE_SENTINEL": (0, "macro keyword"),
"VIR_DEPRECATED": (0, "macro keyword"),
+ "VIR_EXPORT_VAR": (0, "macro keyword"),
"WINAPI": (0, "Windows keyword"),
"__declspec": (3, "Windows keyword"),
"__stdcall": (0, "Windows keyword"),
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 12b8ea1..aaefa09 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -29,6 +29,20 @@ extern "C" {
# endif
#endif /* VIR_DEPRECATED */
+#ifdef WIN32
+# ifdef LIBVIRT_STATIC
+# define VIR_EXPORT_VAR extern
+# else
+# ifdef IN_LIBVIRT
+# define VIR_EXPORT_VAR __declspec(dllexport)
+# else
+# define VIR_EXPORT_VAR __declspec(dllimport) extern
+# endif
+# endif
+#else
+# define VIR_EXPORT_VAR extern
+#endif
+
/**
* virConnect:
*
@@ -499,7 +513,7 @@ struct _virConnectAuth {
typedef struct _virConnectAuth virConnectAuth;
typedef virConnectAuth *virConnectAuthPtr;
-extern virConnectAuthPtr virConnectAuthPtrDefault;
+VIR_EXPORT_VAR virConnectAuthPtr virConnectAuthPtrDefault;
/**
* VIR_UUID_BUFLEN:
diff --git a/src/Makefile.am b/src/Makefile.am
index 08e204d..0aa3443 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -20,7 +20,9 @@ INCLUDES = \
-DLOCAL_STATE_DIR=\""$(localstatedir)"\" \
-DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
$(WARN_CFLAGS) \
- $(LOCK_CHECKING_CFLAGS)
+ $(LOCK_CHECKING_CFLAGS) \
+ -DIN_LIBVIRT \
+ $(WIN32_EXTRA_CFLAGS)
EXTRA_DIST = $(conf_DATA)
--
1.6.3.3