libs: fix 'inconsistent DLL linkage' warnings on Windows

For each lib we build export its own API in headers when we're
building it, otherwise import the API from the headers.

This fixes linker warnings on Windows when building with MSVC.

The problem was that we had defined all GST_*_API decorators
unconditionally to GST_EXPORT. This was intentional and only
supposed to be temporary, but caused linker warnings because
we tell the linker that we want to export all symbols even
those from externall DLLs, and when the linker notices that
they were in external DLLS and not present locally it warns.

What we need to do when building each library is: export
the library's own symbols and import all other symbols. To
this end we define e.g. BUILDING_GST_FOO and then we define
the GST_FOO_API decorator either to export or to import
symbols depending on whether BUILDING_GST_FOO is set or not.
That way external users of each library API automatically
get the import.

https://bugzilla.gnome.org/show_bug.cgi?id=797185
This commit is contained in:
Tim-Philipp Müller 2018-08-25 23:09:12 +02:00
parent 50038bed79
commit 46ed0f0489
16 changed files with 31 additions and 11 deletions

View file

@ -136,7 +136,7 @@ DISTCLEANFILES = $(built_headers_configure)
libgstreamer_@GST_API_VERSION@_la_CFLAGS = \ libgstreamer_@GST_API_VERSION@_la_CFLAGS = \
-D_GNU_SOURCE \ -D_GNU_SOURCE \
-DGST_EXPORTS \ -DBUILDING_GST \
-DG_LOG_DOMAIN=g_log_domain_gstreamer \ -DG_LOG_DOMAIN=g_log_domain_gstreamer \
-DGST_API_VERSION=\""$(GST_API_VERSION)"\" \ -DGST_API_VERSION=\""$(GST_API_VERSION)"\" \
-DGST_DISABLE_DEPRECATED \ -DGST_DISABLE_DEPRECATED \

View file

@ -162,7 +162,11 @@
#endif #endif
#ifndef GST_API #ifndef GST_API
# ifdef BUILDING_GST
#define GST_API GST_EXPORT #define GST_API GST_EXPORT
# else
# define GST_API GST_API_IMPORT
# endif
#endif #endif
/* These macros are used to mark deprecated functions in GStreamer headers, /* These macros are used to mark deprecated functions in GStreamer headers,

View file

@ -219,7 +219,6 @@ subdir('printf')
libgst_c_args = gst_c_args + [ libgst_c_args = gst_c_args + [
'-D_GNU_SOURCE', '-D_GNU_SOURCE',
'-DGST_EXPORTS',
'-DG_LOG_DOMAIN=g_log_domain_gstreamer', '-DG_LOG_DOMAIN=g_log_domain_gstreamer',
'-DGST_DISABLE_DEPRECATED', '-DGST_DISABLE_DEPRECATED',
] ]
@ -237,7 +236,7 @@ libgst = library('gstreamer-1.0', gst_sources,
version : libversion, version : libversion,
soversion : soversion, soversion : soversion,
darwin_versions : osxversion, darwin_versions : osxversion,
c_args : libgst_c_args, c_args : libgst_c_args + ['-DBUILDING_GST'],
include_directories : [configinc, include_directories : [configinc,
# HACK, change include paths in .y and .l in final version. # HACK, change include paths in .y and .l in final version.
include_directories('parse')], include_directories('parse')],

View file

@ -14,7 +14,7 @@ EXTRA_DIST = \
nodist_libgstparse_la_SOURCES = lex.priv_gst_parse_yy.c grammar.tab.c grammar.tag.h parse_lex.h nodist_libgstparse_la_SOURCES = lex.priv_gst_parse_yy.c grammar.tab.c grammar.tag.h parse_lex.h
CLEANFILES += grammar.tab.c lex.priv_gst_parse_yy.c CLEANFILES += grammar.tab.c lex.priv_gst_parse_yy.c
libgstparse_la_CFLAGS = $(GST_ALL_CFLAGS) -DGST_EXPORTS -DYYMALLOC=g_malloc -DYYFREE=g_free libgstparse_la_CFLAGS = $(GST_ALL_CFLAGS) -DBUILDING_GST -DYYMALLOC=g_malloc -DYYFREE=g_free
libgstparse_la_LIBADD = $(GST_ALL_LIBS) libgstparse_la_LIBADD = $(GST_ALL_LIBS)
noinst_HEADERS = types.h noinst_HEADERS = types.h

View file

@ -20,7 +20,7 @@ libgstbase_@GST_API_VERSION@_la_SOURCES = \
gstqueuearray.c \ gstqueuearray.c \
gsttypefindhelper.c gsttypefindhelper.c
libgstbase_@GST_API_VERSION@_la_CFLAGS = $(GST_OBJ_CFLAGS) libgstbase_@GST_API_VERSION@_la_CFLAGS = $(GST_OBJ_CFLAGS) -DBUILDING_GST_BASE
libgstbase_@GST_API_VERSION@_la_LIBADD = $(GST_OBJ_LIBS) libgstbase_@GST_API_VERSION@_la_LIBADD = $(GST_OBJ_LIBS)
libgstbase_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS) libgstbase_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS)

View file

@ -25,7 +25,11 @@
#include <gst/gst.h> #include <gst/gst.h>
#ifndef GST_BASE_API #ifndef GST_BASE_API
#ifdef BUILDING_GST_BASE
#define GST_BASE_API GST_EXPORT #define GST_BASE_API GST_EXPORT
#else
#define GST_BASE_API GST_API_IMPORT
#endif
#endif #endif
#endif /* __GST_BASE_PRELUDE_H__ */ #endif /* __GST_BASE_PRELUDE_H__ */

View file

@ -42,7 +42,7 @@ gst_base_gen_sources = []
gst_base = library('gstbase-@0@'.format(apiversion), gst_base = library('gstbase-@0@'.format(apiversion),
gst_base_sources, gst_base_sources,
c_args : gst_c_args, c_args : gst_c_args + ['-DBUILDING_GST_BASE'],
version : libversion, version : libversion,
soversion : soversion, soversion : soversion,
darwin_versions : osxversion, darwin_versions : osxversion,

View file

@ -14,6 +14,7 @@ libgstcheck_@GST_API_VERSION@_la_SOURCES = \
libgstcheck_@GST_API_VERSION@_la_CFLAGS = $(GST_OBJ_CFLAGS) \ libgstcheck_@GST_API_VERSION@_la_CFLAGS = $(GST_OBJ_CFLAGS) \
-UG_DISABLE_ASSERT \ -UG_DISABLE_ASSERT \
-DBUILDING_GST_CHECK \
-I$(top_builddir)/libs \ -I$(top_builddir)/libs \
-I$(top_builddir)/libs/gst/check \ -I$(top_builddir)/libs/gst/check \
-I$(top_builddir)/libs/gst/check/libcheck -I$(top_builddir)/libs/gst/check/libcheck

View file

@ -25,7 +25,11 @@
#include <gst/gst.h> #include <gst/gst.h>
#ifndef GST_CHECK_API #ifndef GST_CHECK_API
#ifdef BUILDING_GST_CHECK
#define GST_CHECK_API GST_EXPORT #define GST_CHECK_API GST_EXPORT
#else
#define GST_CHECK_API GST_API_IMPORT
#endif
#endif #endif
#ifndef GST_DISABLE_DEPRECATED #ifndef GST_DISABLE_DEPRECATED

View file

@ -39,7 +39,7 @@ configure_file(input : 'libcheck/check.h.in',
gst_check = shared_library('gstcheck-@0@'.format(apiversion), gst_check = shared_library('gstcheck-@0@'.format(apiversion),
gst_check_sources, gst_check_sources,
c_args : gst_c_args + ['-DGST_EXPORTS', '-UG_DISABLE_ASSERT'], c_args : gst_c_args + ['-UG_DISABLE_ASSERT', '-DBUILDING_GST_CHECK'],
version : libversion, version : libversion,
soversion : soversion, soversion : soversion,
darwin_versions : osxversion, darwin_versions : osxversion,

View file

@ -40,7 +40,7 @@ libgstcontroller_@GST_API_VERSION@_la_SOURCES = \
nodist_libgstcontroller_@GST_API_VERSION@_la_SOURCES = $(BUILT_SOURCES) nodist_libgstcontroller_@GST_API_VERSION@_la_SOURCES = $(BUILT_SOURCES)
libgstcontroller_@GST_API_VERSION@_la_CFLAGS = $(GST_OBJ_CFLAGS) libgstcontroller_@GST_API_VERSION@_la_CFLAGS = $(GST_OBJ_CFLAGS) -DBUILDING_GST_CONTROLLER
libgstcontroller_@GST_API_VERSION@_la_LIBADD = $(GST_OBJ_LIBS) $(LIBM) libgstcontroller_@GST_API_VERSION@_la_LIBADD = $(GST_OBJ_LIBS) $(LIBM)
libgstcontroller_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS) libgstcontroller_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS)

View file

@ -25,7 +25,11 @@
#include <gst/gst.h> #include <gst/gst.h>
#ifndef GST_CONTROLLER_API #ifndef GST_CONTROLLER_API
#ifdef BUILDING_GST_CONTROLLER
#define GST_CONTROLLER_API GST_EXPORT #define GST_CONTROLLER_API GST_EXPORT
#else
#define GST_CONTROLLER_API GST_API_IMPORT
#endif
#endif #endif
#endif /* __GST_CONTROLLER_PRELUDE_H__ */ #endif /* __GST_CONTROLLER_PRELUDE_H__ */

View file

@ -38,7 +38,7 @@ gstcontroller_h = controller_enums[1]
gst_controller_gen_sources = [gstcontroller_h] gst_controller_gen_sources = [gstcontroller_h]
gst_controller = library('gstcontroller-@0@'.format(apiversion), gst_controller = library('gstcontroller-@0@'.format(apiversion),
gst_controller_sources, gstcontroller_h, gstcontroller_c, gst_controller_sources, gstcontroller_h, gstcontroller_c,
c_args : gst_c_args, c_args : gst_c_args + ['-DBUILDING_GST_CONTROLLER'],
install : true, install : true,
version : libversion, version : libversion,
soversion : soversion, soversion : soversion,

View file

@ -24,7 +24,7 @@ libgstnet_@GST_API_VERSION@_la_SOURCES = \
noinst_HEADERS = gstptp_private.h gstntppacket.h gstnetutils.h noinst_HEADERS = gstptp_private.h gstntppacket.h gstnetutils.h
libgstnet_@GST_API_VERSION@_la_CFLAGS = $(GST_OBJ_CFLAGS) $(GIO_CFLAGS) libgstnet_@GST_API_VERSION@_la_CFLAGS = $(GST_OBJ_CFLAGS) $(GIO_CFLAGS) -DBUILDING_GST_NET
libgstnet_@GST_API_VERSION@_la_LIBADD = $(GST_OBJ_LIBS) $(GIO_LIBS) \ libgstnet_@GST_API_VERSION@_la_LIBADD = $(GST_OBJ_LIBS) $(GIO_LIBS) \
$(top_builddir)/libs/gst/base/libgstbase-@GST_API_VERSION@.la $(top_builddir)/libs/gst/base/libgstbase-@GST_API_VERSION@.la
libgstnet_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS) libgstnet_@GST_API_VERSION@_la_LDFLAGS = $(GST_LIB_LDFLAGS) $(GST_ALL_LDFLAGS) $(GST_LT_LDFLAGS)

View file

@ -25,7 +25,7 @@ install_headers(gst_net_headers, subdir : 'gstreamer-1.0/gst/net/')
gst_net_gen_sources = [] gst_net_gen_sources = []
gst_net = library('gstnet-@0@'.format(apiversion), gst_net = library('gstnet-@0@'.format(apiversion),
gst_net_sources, gst_net_sources,
c_args : gst_c_args, c_args : gst_c_args + ['-DBUILDING_GST_NET'],
include_directories : [configinc, libsinc], include_directories : [configinc, libsinc],
version : libversion, version : libversion,
soversion : soversion, soversion : soversion,

View file

@ -25,7 +25,11 @@
#include <gst/gst.h> #include <gst/gst.h>
#ifndef GST_NET_API #ifndef GST_NET_API
#ifdef BUILDING_GST_NET
#define GST_NET_API GST_EXPORT #define GST_NET_API GST_EXPORT
#else
#define GST_NET_API GST_API_IMPORT
#endif
#endif #endif
#endif /* __GST_NET_PRELUDE_H__ */ #endif /* __GST_NET_PRELUDE_H__ */