From: Chun-wei Fan Date: Tue, 7 Mar 2023 06:27:06 +0000 (+0800) Subject: modules/media: Fix Visual Studio builds with older GLib X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~5^2~39^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=432e8664e1eb24c81bbcf1927f0de257bae7e038;p=gtk4.git modules/media: Fix Visual Studio builds with older GLib The current definitions of the g_io_module_*() symbols do not build on Visual Studio when building against GLib earlier than 2.75.0 due to the way how these symbols are decorated in the GLib headers, as Visual Studio does not allow symbols that were previously marked with 'extern' (or so) to be marked with anything that is symantically different later. As a result, if we are using Visual Studio and glib-2.74.x or earlier, override _GLIB_EXTERN as appropriate in the modules/media sources before including the GIO headers. This sadly, means that we need a configure-time check as it would have been too late if we checked the GLib version using G_VERSION_CHECK macro, as the GIO headers would have been included already. There are similar items in the print backends, but we will not attempt to update these files as they are not meant to be built for Windows. --- diff --git a/meson.build b/meson.build index 07912b124e..3f05b7b9c6 100644 --- a/meson.build +++ b/meson.build @@ -370,6 +370,13 @@ glib_dep = dependency('glib-2.0', version: glib_req) gobject_dep = dependency('gobject-2.0', version: glib_req) if os_win32 giowin32_dep = dependency('gio-windows-2.0', version: glib_req, required: win32_enabled) + if giowin32_dep.version().version_compare('<2.75.0') + if cc.get_id() == 'msvc' and get_option('default_library') != 'static' + # Override _GLIB_EXTERN on Visual Studio for media modules for glib <= 2.74.x, so that we + # avoid error C2375 (redefinition; different linkage) when building the g_io_module_*() bits + cdata.set('MODULES_OVERRIDE_GLIB_EXTERN', true) + endif + endif endif if os_unix giounix_dep = dependency('gio-unix-2.0', version: glib_req, required: false) diff --git a/modules/media/gtkffmediafile.c b/modules/media/gtkffmediafile.c index 2839cb8174..0103e5bd16 100644 --- a/modules/media/gtkffmediafile.c +++ b/modules/media/gtkffmediafile.c @@ -19,6 +19,15 @@ #include "config.h" +/* + * Sadly, we need this to build on Visual Studio against glib-2.74.x or earlier, + * otherwise the build will fail when building the g_io_module_*() bits with error C2375 + * (redefinition; different linkage). This must be before including the Gio headers. + */ +#if defined (_MSC_VER) && defined (MODULES_OVERRIDE_GLIB_EXTERN) +# define _GLIB_EXTERN __declspec(dllexport) extern +#endif + #include "gtkffmediafileprivate.h" #include diff --git a/modules/media/gtkgstmediafile.c b/modules/media/gtkgstmediafile.c index 5487bb0571..7353539ef6 100644 --- a/modules/media/gtkgstmediafile.c +++ b/modules/media/gtkgstmediafile.c @@ -19,6 +19,15 @@ #include "config.h" +/* + * Sadly, we need this to build on Visual Studio against glib-2.74.x or earlier, + * otherwise the build will fail when building the g_io_module_*() bits with error C2375 + * (redefinition; different linkage). This must be before including the Gio headers. + */ +#if defined (_MSC_VER) && defined (MODULES_OVERRIDE_GLIB_EXTERN) +# define _GLIB_EXTERN __declspec(dllexport) extern +#endif + #include "gtkgstmediafileprivate.h" #include "gtkgstpaintableprivate.h"