From acd9c12667a021936b30e0fa8f43d3a8c7133cf7 Mon Sep 17 00:00:00 2001 From: Chun-wei Fan Date: Thu, 4 Jun 2020 16:27:56 +0800 Subject: [PATCH] modules: Fix build on Visual Studio Visual Studio does not allow decorating functions with '__declspec (dllexport)' if a prototype exists and is not decorated with '__declspec (dllexport)' as well, so we cannot just decorate g_io_module_[load|unload|query] in the various module sources with G_MODULE_EXPORT because the prototypes of these functions have been marked with _GLIB_EXTERN, which equates to 'extern' unless overridden Fix this by overriding _GLIB_EXTERN with the appropriate visibility flag, as we have used to define _GDK_EXTERN. Unfortunately, we can't just use _GDK_EXTERN G_MODULE_EXPORT as they may have not been defined yet for our use Do this across the board for all modules, even if they are not buildable on Visual Studio nor Windows, for consistency's sake. --- meson.build | 16 ++++++++++------ modules/media/gtkgstmediafile.c | 3 --- modules/media/meson.build | 6 +++++- .../printbackends/gtkprintbackendcloudprint.c | 3 --- modules/printbackends/gtkprintbackendcups.c | 3 --- modules/printbackends/gtkprintbackendfile.c | 3 --- modules/printbackends/gtkprintbackendlpr.c | 3 --- modules/printbackends/meson.build | 1 + 8 files changed, 16 insertions(+), 22 deletions(-) diff --git a/meson.build b/meson.build index 9295163603..946027a278 100644 --- a/meson.build +++ b/meson.build @@ -286,15 +286,19 @@ endif common_cflags = cc.get_supported_arguments(test_cflags) # Symbol visibility + +if os_win32 + visibility_define = '__declspec(dllexport) extern' +else + visibility_define = '__attribute__((visibility("default"))) extern' +endif + if get_option('default_library') != 'static' + cdata.set('_GDK_EXTERN', visibility_define) if os_win32 cdata.set('DLL_EXPORT', true) - cdata.set('_GDK_EXTERN', '__declspec(dllexport) extern') - if cc.get_id() != 'msvc' - common_cflags += ['-fvisibility=hidden'] - endif - else - cdata.set('_GDK_EXTERN', '__attribute__((visibility("default"))) extern') + endif + if cc.get_id() != 'msvc' common_cflags += ['-fvisibility=hidden'] endif endif diff --git a/modules/media/gtkgstmediafile.c b/modules/media/gtkgstmediafile.c index 5988ef38c3..b094796fd5 100644 --- a/modules/media/gtkgstmediafile.c +++ b/modules/media/gtkgstmediafile.c @@ -97,7 +97,6 @@ G_DEFINE_TYPE_EXTENDED (GtkGstMediaFile, gtk_gst_media_file, GTK_TYPE_MEDIA_FILE G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE, gtk_gst_media_file_paintable_init)) -G_MODULE_EXPORT void g_io_module_load (GIOModule *module) { @@ -109,7 +108,6 @@ g_io_module_load (GIOModule *module) 10); } -G_MODULE_EXPORT G_GNUC_NORETURN void g_io_module_unload (GIOModule *module) @@ -117,7 +115,6 @@ g_io_module_unload (GIOModule *module) g_assert_not_reached (); } -G_MODULE_EXPORT char ** g_io_module_query (void) { diff --git a/modules/media/meson.build b/modules/media/meson.build index c6dbed1f26..59124d3154 100644 --- a/modules/media/meson.build +++ b/modules/media/meson.build @@ -23,7 +23,11 @@ endif media_subdir = 'gtk-4.0/@0@/media'.format(gtk_binary_version) media_install_dir = join_paths(get_option('libdir'), media_subdir) -extra_c_args = ['-DGTK_COMPILATION'] +extra_c_args = [ + '-DGTK_COMPILATION', + '-D_GLIB_EXTERN=@0@'.format(visibility_define), +] + extra_c_args += common_cflags if media_backends.contains('ffmpeg') diff --git a/modules/printbackends/gtkprintbackendcloudprint.c b/modules/printbackends/gtkprintbackendcloudprint.c index 99dc5f3665..6a5d7755af 100644 --- a/modules/printbackends/gtkprintbackendcloudprint.c +++ b/modules/printbackends/gtkprintbackendcloudprint.c @@ -103,7 +103,6 @@ void t_goa_account_free (gpointer data); G_DEFINE_DYNAMIC_TYPE (GtkPrintBackendCloudprint, gtk_print_backend_cloudprint, GTK_TYPE_PRINT_BACKEND) -G_MODULE_EXPORT void g_io_module_load (GIOModule *module) { @@ -119,13 +118,11 @@ g_io_module_load (GIOModule *module) 10); } -G_MODULE_EXPORT void g_io_module_unload (GIOModule *module) { } -G_MODULE_EXPORT char ** g_io_module_query (void) { diff --git a/modules/printbackends/gtkprintbackendcups.c b/modules/printbackends/gtkprintbackendcups.c index 58dd95bbbe..893ced4c16 100644 --- a/modules/printbackends/gtkprintbackendcups.c +++ b/modules/printbackends/gtkprintbackendcups.c @@ -236,7 +236,6 @@ static void secrets_service_vanished_cb (GDBusConnec G_DEFINE_DYNAMIC_TYPE(GtkPrintBackendCups, gtk_print_backend_cups, GTK_TYPE_PRINT_BACKEND) -G_MODULE_EXPORT void g_io_module_load (GIOModule *module) { @@ -251,13 +250,11 @@ g_io_module_load (GIOModule *module) 10); } -G_MODULE_EXPORT void g_io_module_unload (GIOModule *module) { } -G_MODULE_EXPORT char ** g_io_module_query (void) { diff --git a/modules/printbackends/gtkprintbackendfile.c b/modules/printbackends/gtkprintbackendfile.c index 3486805688..071ebec359 100644 --- a/modules/printbackends/gtkprintbackendfile.c +++ b/modules/printbackends/gtkprintbackendfile.c @@ -102,7 +102,6 @@ static GtkPageSetup * file_printer_get_default_page_size (GtkPrinter G_DEFINE_DYNAMIC_TYPE(GtkPrintBackendFile, gtk_print_backend_file, GTK_TYPE_PRINT_BACKEND) -G_MODULE_EXPORT void g_io_module_load (GIOModule *module) { @@ -116,13 +115,11 @@ g_io_module_load (GIOModule *module) 10); } -G_MODULE_EXPORT void g_io_module_unload (GIOModule *module) { } -G_MODULE_EXPORT char ** g_io_module_query (void) { diff --git a/modules/printbackends/gtkprintbackendlpr.c b/modules/printbackends/gtkprintbackendlpr.c index 0626e594fa..cef1501c30 100644 --- a/modules/printbackends/gtkprintbackendlpr.c +++ b/modules/printbackends/gtkprintbackendlpr.c @@ -83,7 +83,6 @@ static void gtk_print_backend_lpr_print_stream (GtkPrintBacke G_DEFINE_DYNAMIC_TYPE (GtkPrintBackendLpr, gtk_print_backend_lpr, GTK_TYPE_PRINT_BACKEND) -G_MODULE_EXPORT void g_io_module_load (GIOModule *module) { @@ -97,13 +96,11 @@ g_io_module_load (GIOModule *module) 10); } -G_MODULE_EXPORT void g_io_module_unload (GIOModule *module) { } -G_MODULE_EXPORT char ** g_io_module_query (void) { diff --git a/modules/printbackends/meson.build b/modules/printbackends/meson.build index 643a8ba888..40a9379b47 100644 --- a/modules/printbackends/meson.build +++ b/modules/printbackends/meson.build @@ -68,6 +68,7 @@ printbackends_args = [ '-DGTK_COMPILATION', '-DGTK_DISABLE_DEPRECATION_WARNINGS', '-DGTK_PRINT_BACKEND_ENABLE_UNSUPPORTED', + '-D_GLIB_EXTERN=@0@'.format(visibility_define), ] + common_cflags if print_backends.contains('cups')