win32: Don't use dllexport/import when only building statically
authorNirbheek Chauhan <nirbheek@centricular.com>
Tue, 21 Jun 2016 14:19:15 +0000 (19:49 +0530)
committerTim-Philipp Müller <tim@centricular.com>
Thu, 23 Jun 2016 22:39:45 +0000 (23:39 +0100)
If the prototypes in the public API have dllimport in them when building
statically on Windows, the compiler will look for symbols with symbol
mangling and indirection corresponding to a DLL. This will cause a build
failure when trying to link tests/examples/etc.

External users of GStreamer also need to define -DGST_STATIC_COMPILATION
if they want to link to static gstreamer libraries on Windows.

A similar version of this patch has been committed to all gstreamer
repositories.

https://bugzilla.gnome.org/show_bug.cgi?id=767463

configure.ac
gst/gstconfig.h.in

index d40d33a..6aa06e3 100644 (file)
@@ -188,6 +188,12 @@ fi
 AC_SUBST(GST_PLUGIN_LIBTOOLFLAGS)
 AM_CONDITIONAL(GST_PLUGIN_BUILD_STATIC, test "x$enable_static_plugins" = "xyes")
 
+dnl If only building static libraries, define GST_STATIC_COMPILATION. This is
+dnl needed only on Windows, but it doesn't hurt to have it everywhere.
+if test x$enable_static = xyes -a x$enable_shared = xno; then
+  GST_OBJ_STATIC_CFLAGS="-DGST_STATIC_COMPILATION"
+fi
+
 dnl building of tests
 AC_ARG_ENABLE(tests,
   AS_HELP_STRING([--disable-tests],[disable building test apps]),
@@ -950,8 +956,8 @@ AC_SUBST(GST_LIB_LDFLAGS)
 dnl GST_OBJ_*
 dnl default vars for all internal objects built on libgstreamer
 dnl includes GST_ALL_*
-GST_OBJ_CFLAGS="\$(GST_ALL_CFLAGS)"
-GST_OBJ_CXXFLAGS="\$(GST_ALL_CXXFLAGS)"
+GST_OBJ_CFLAGS="\$(GST_ALL_CFLAGS) $GST_OBJ_STATIC_CFLAGS"
+GST_OBJ_CXXFLAGS="\$(GST_ALL_CXXFLAGS) $GST_OBJ_STATIC_CFLAGS"
 GST_OBJ_LIBS="\$(top_builddir)/gst/libgstreamer-$GST_API_VERSION.la \$(GST_ALL_LIBS)"
 AC_SUBST(GST_OBJ_CFLAGS)
 AC_SUBST(GST_OBJ_CXXFLAGS)
index 41f76b6..8a951fb 100644 (file)
  * On Windows, this exports the plugin definition from the DLL.
  * On other platforms, this gets defined as a no-op.
  */
-#ifdef _WIN32 /* Both 32-bit and 64-bit; both GCC and MSVC */
+/* Macro _WIN32 is defined on 32-bit and 64-bit Windows; by both GCC and MSVC
+ *
+ * NOTE: To link to Windows statically on Windows, you must define
+ * GST_STATIC_COMPILATION or the prototypes will cause the compiler to search
+ * for the symbol inside a DLL
+ */
+#if defined(_WIN32) && !defined(GST_STATIC_COMPILATION)
 # define GST_PLUGIN_EXPORT __declspec(dllexport) extern
 # ifdef GST_EXPORTS
 #  define GST_EXPORT __declspec(dllexport) extern