From b6e69ffdfb3bb21dbada8f01b488ae877f8d205c Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Thu, 8 Sep 2016 12:58:54 +0530 Subject: [PATCH] gstconfig: Use __declspec when built with MinGW and linking with MSVC Earlier we were only using __declspec(dllexport/import) when we were built with MSVC because when built with MinGW and linking with MinGW we don't need it (and we get linker errors because of it). However, when we're built with MinGW and someone wants to link to us with MSVC, we still need the prototypes to have __declspec(dllimport) since MSVC cannot do auto-import like GCC can. https://bugzilla.gnome.org/show_bug.cgi?id=771029 --- configure.ac | 4 ++-- gst/gstconfig.h.in | 9 ++++++--- meson.build | 16 ++++++++-------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 71f8280..f2def0e 100644 --- a/configure.ac +++ b/configure.ac @@ -133,8 +133,8 @@ AG_GST_SET_PACKAGE_RELEASE_DATETIME_WITH_NANO([$PACKAGE_VERSION_NANO], # We only use this when building with MSVC, which is only done with the # alternate Meson build system files -GSTCONFIG_USE_MSVC_DECLSPEC=0 -AC_SUBST(GSTCONFIG_USE_MSVC_DECLSPEC) +GSTCONFIG_BUILT_WITH_MSVC=0 +AC_SUBST(GSTCONFIG_BUILT_WITH_MSVC) dnl check for bash completion AC_ARG_WITH([bash-completion-dir], diff --git a/gst/gstconfig.h.in b/gst/gstconfig.h.in index f39b601..c2e8361 100644 --- a/gst/gstconfig.h.in +++ b/gst/gstconfig.h.in @@ -128,14 +128,17 @@ * On Windows, this exports the plugin definition from the DLL. * On other platforms, this gets defined as a no-op. */ -/* Only use __declspec(dllexport/import) when we have been built with MSVC. - * With MinGW we still rely on the linker to auto-export/import symbols. +/* Only use __declspec(dllexport/import) when we have been built with MSVC or + * the user is linking to us with MSVC. The only remaining case is when we were + * built with MinGW and are linking with MinGW in which case we rely on the + * linker to auto-export/import symbols. Of course all this is only used when + * not linking statically. * * NOTE: To link to GStreamer 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 @GSTCONFIG_USE_MSVC_DECLSPEC@ && !defined(GST_STATIC_COMPILATION) +#if (@GSTCONFIG_BUILT_WITH_MSVC@ || defined(_MSC_VER)) && !defined(GST_STATIC_COMPILATION) # define GST_PLUGIN_EXPORT __declspec(dllexport) # ifdef GST_EXPORTS # define GST_EXPORT __declspec(dllexport) diff --git a/meson.build b/meson.build index a7e0197..f80fd99 100644 --- a/meson.build +++ b/meson.build @@ -187,6 +187,14 @@ if cc.has_type('ptrdiff_t') cdata.set('HAVE_PTRDIFF_T') endif +# We only want to use the __declspec(dllexport/import) dance in GST_EXPORT when +# building with MSVC +if cc.get_id() == 'msvc' + cdata.set('GSTCONFIG_BUILT_WITH_MSVC', 1) +else + cdata.set('GSTCONFIG_BUILT_WITH_MSVC', 0) +endif + # ------------------------------------------------------------------------------------- # config.h things needed by libcheck (FIXME: move into the libcheck meson.build) (tpm) # ------------------------------------------------------------------------------------- @@ -221,14 +229,6 @@ if cc.has_function('strsignal', prefix : '#include ') cdata.set('HAVE_DECL_STRSIGNAL', 1) endif -# We only want to use the __declspec(dllexport/import) dance in GST_EXPORT when -# building with MSVC -if cc.get_id() == 'msvc' - cdata.set('GSTCONFIG_USE_MSVC_DECLSPEC', 1) -else - cdata.set('GSTCONFIG_USE_MSVC_DECLSPEC', 0) -endif - configure_file(input : 'config.h.meson', output : 'config.h', configuration : cdata) -- 2.7.4