Commit b6411ae7 authored by Tim-Philipp Müller's avatar Tim-Philipp Müller
Browse files

libs: fix API export/import and 'inconsistent linkage' on MSVC

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.

While we're at it, add new GST_API_EXPORT in config.h and use
that for GST_*_API decorators instead of GST_EXPORT.

The right export define depends on the toolchain and whether
we're using -fvisibility=hidden or not, so it's better to set it
to the right thing directly than hard-coding a compiler whitelist
in the public header.

We put the export define into config.h instead of passing it via the
command line to the compiler because it might contain spaces and brackets
and in the autotools scenario we'd have to pass that through multiple
layers of plumbing and Makefile/shell escaping and we're just not going
to be *that* lucky.

The export define is only used if we're compiling our lib, not by external
users of the lib headers, so it's not a problem to put it into config.h

Also, this means all .c files of libs need to include config.h
to get the export marker defined, so fix up a few that didn't
include config.h.

This commit depends on a common submodule commit that makes gst-glib-gen.mak
add an #include "config.h" to generated enum/marshal .c files for the
autotools build.

https://bugzilla.gnome.org/show_bug.cgi?id=797185
parent be3edc6a
common @ cd1dee06
Subproject commit ed78bee437dcbe22e6eef0031d9a29d157c0461f
Subproject commit cd1dee06bf07f094677d0cf3eea4a2e8c2636b24
......@@ -2485,7 +2485,13 @@ fi
AC_SUBST(DEPRECATED_CFLAGS)
VISIBILITY_CFLAGS=""
AS_COMPILER_FLAG([-fvisibility=hidden], [VISIBILITY_CFLAGS="-fvisibility=hidden"])
AS_COMPILER_FLAG([-fvisibility=hidden], [
VISIBILITY_CFLAGS="-fvisibility=hidden"
AC_DEFINE(GST_API_EXPORT, [extern __attribute__ ((visibility ("default")))], [public symbol export define])
], [
VISIBILITY_CFLAGS=""
AC_DEFINE(GST_API_EXPORT, [extern], [public symbol export define])
])
AC_SUBST(VISIBILITY_CFLAGS)
VISIBILITY_CXXFLAGS=""
......
......@@ -14,6 +14,7 @@ libgstadaptivedemux_@GST_API_VERSION@_la_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) \
-DGST_USE_UNSTABLE_API \
-DBUILDING_GST_ADAPTIVE_DEMUX \
$(GST_CFLAGS)
libgstadaptivedemux_@GST_API_VERSION@_la_LIBADD = \
$(top_builddir)/gst-libs/gst/uridownloader/libgsturidownloader-$(GST_API_VERSION).la \
......
......@@ -25,7 +25,11 @@
#include <gst/gst.h>
#ifndef GST_ADAPTIVE_DEMUX_API
#define GST_ADAPTIVE_DEMUX_API GST_EXPORT
# ifdef BUILDING_GST_ADAPTIVE_DEMUX
# define GST_ADAPTIVE_DEMUX_API GST_API_EXPORT /* from config.h */
# else
# define GST_ADAPTIVE_DEMUX_API GST_API_IMPORT
# endif
#endif
#endif /* __GST_ADAPTIVE_DEMUX_PRELUDE_H__ */
gstadaptivedemux = library('gstadaptivedemux-' + api_version,
'gstadaptivedemux.c',
c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API'],
c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API', '-DBUILDING_GST_ADAPTIVE_DEMUX'],
include_directories : [configinc, libsinc],
version : libversion,
soversion : soversion,
......
......@@ -11,6 +11,7 @@ nodist_libgstbadaudio_@GST_API_VERSION@_la_SOURCES = $(BUILT_SOURCES)
libgstbadaudio_@GST_API_VERSION@_la_CFLAGS = \
-DGST_USE_UNSTABLE_API \
-DBUILDING_GST_AUDIO_BAD \
-I$(top_srcdir)/gst-libs \
-I$(top_builddir)/gst-libs \
$(GST_CFLAGS) $(ORC_CFLAGS) \
......
......@@ -25,7 +25,11 @@
#include <gst/gst.h>
#ifndef GST_AUDIO_BAD_API
#define GST_AUDIO_BAD_API GST_EXPORT
# ifdef BUILDING_GST_AUDIO_BAD
# define GST_AUDIO_BAD_API GST_API_EXPORT /* from config.h */
# else
# define GST_AUDIO_BAD_API GST_API_IMPORT
# endif
#endif
#endif /* __GST_AUDIO_BAD_PRELUDE_H__ */
......@@ -27,6 +27,9 @@
* non-interleaved (planar) audio buffers. Before using, an audio format
* must be configured with gst_planar_audio_adapter_configure()
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstplanaraudioadapter.h"
......
......@@ -5,7 +5,7 @@ install_headers(badaudio_headers, subdir : 'gstreamer-1.0/gst/audio')
gstbadaudio = library('gstbadaudio-' + api_version,
badaudio_sources,
c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API'],
c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API', '-DBUILDING_GST_AUDIO_BAD'],
include_directories : [configinc, libsinc],
version : libversion,
soversion : soversion,
......
......@@ -19,6 +19,7 @@ libgstbasecamerabinsrc_@GST_API_VERSION@_la_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) \
$(GST_PLUGINS_BASE_CFLAGS) \
-DGST_USE_UNSTABLE_API \
-DBUILDING_GST_BASE_CAMERA_BIN_SRC \
$(GST_CFLAGS)
libgstbasecamerabinsrc_@GST_API_VERSION@_la_LIBADD = \
-lgstapp-$(GST_API_VERSION) $(GST_PLUGINS_BASE_LIBS) $(GST_BASE_LIBS) $(GST_LIBS)
......
......@@ -25,7 +25,11 @@
#include <gst/gst.h>
#ifndef GST_BASE_CAMERA_BIN_SRC_API
#define GST_BASE_CAMERA_BIN_SRC_API GST_EXPORT
# ifdef BUILDING_GST_BASE_CAMERA_BIN_SRC
# define GST_BASE_CAMERA_BIN_SRC_API GST_API_EXPORT /* from config.h */
# else
# define GST_BASE_CAMERA_BIN_SRC_API GST_API_IMPORT
# endif
#endif
#endif /* __GST_BASE_CAMERA_BIN_SRC_PRELUDE_H__ */
......@@ -17,6 +17,9 @@
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstcamerabin-enum.h"
......
......@@ -26,6 +26,10 @@
* #GstCameraBinVideo.
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/app/gstappsrc.h>
#include <gst/app/gstappsink.h>
#include <gst/glib-compat-private.h>
......
......@@ -13,7 +13,7 @@ install_headers(camerabin_headers, subdir : 'gstreamer-1.0/gst/basecamerabinsrc'
gstbasecamerabin = library('gstbasecamerabinsrc-' + api_version,
camerabin_sources,
c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API'],
c_args : gst_plugins_bad_args + ['-DGST_USE_UNSTABLE_API', '-DBUILDING_GST_BASE_CAMERA_BIN_SRC'],
include_directories : [configinc, libsinc],
version : libversion,
soversion : soversion,
......
......@@ -26,6 +26,7 @@ libgstcodecparsers_@GST_API_VERSION@include_HEADERS = \
libgstcodecparsers_@GST_API_VERSION@_la_CFLAGS = \
$(GST_PLUGINS_BAD_CFLAGS) \
-DGST_USE_UNSTABLE_API \
-DBUILDING_GST_CODEC_PARSERS \
$(GST_CFLAGS) \
-Dvp8_norm=gst_codecparsers_vp8_norm \
-Dvp8dx_start_decode=gst_codecparsers_vp8dx_start_decode \
......
......@@ -25,7 +25,11 @@
#include <gst/gst.h>
#ifndef GST_CODEC_PARSERS_API
#define GST_CODEC_PARSERS_API GST_EXPORT
# ifdef BUILDING_GST_CODEC_PARSERS
# define GST_CODEC_PARSERS_API GST_API_EXPORT /* from config.h */
# else
# define GST_CODEC_PARSERS_API GST_API_IMPORT
# endif
#endif
#endif /* __GST_CODEC_PARSERS_PRELUDE_H__ */
......@@ -7,7 +7,9 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "dboolhuff.h"
......
......@@ -24,6 +24,9 @@
* @short_description: Manage JPEG 2000 sampling and colorspace fields
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstjpeg2000sampling.h"
......
......@@ -26,6 +26,9 @@
* Provides useful functions for parsing JPEG images
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <string.h>
#include <stdlib.h>
......
......@@ -7,6 +7,9 @@
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "gstvp8rangedecoder.h"
#include "dboolhuff.h"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment