[vlc-devel] [PATCH] Fix libmod_plugin undefined __imp_ symbols building for win32

Konstantinos Tsanaktsidis kjtsanaktsidis at gmail.com
Thu Jun 12 16:34:46 CEST 2014

When building current HEAD of master for x86_64-w64-mingw32 against current
contribs, compilation fails at libmod_plugin due to undefined symbols of
the form __imp_ModPlug_*. This patch modifies libmodplug in contribs by
adding -DMODPLUG_STATIC to CFlags in the pkg-config file. A bug is also
fixed in the main build system to make sure the CFLAGS are picked up from
this pkg-config file.

This problem occurs because of the following code in
contrib/x86_64-w64-mingw32/include/libmodplug/modplug.h. This code is
present in libmodplug obtained from running "make fetch & make" in the
contribs directory, but not present in the prebuilt contribs obtained from
running "make prebuilt".

 #if defined(_WIN32) || defined(__CYGWIN__)
 # if defined(MODPLUG_BUILD) && defined(DLL_EXPORT)
 #   define MODPLUG_EXPORT __declspec(dllexport)
 # elif defined(MODPLUG_BUILD) || defined(MODPLUG_STATIC)
 #   define MODPLUG_EXPORT
 # else
 #   define MODPLUG_EXPORT __declspec(dllimport)
 # endif

When building for Windows, if MODPLUG_STATIC is not defined, MODPLUG_EXPORT
is defined as "__declspec(dllimport)". On Windows, dynamic symbols are
prefixed with "__imp_", so this causes GCC to adjust the symbol references
to the libmodplug functions accordingly.

This patch therefore adds a patch to contribs for libmodplug's pkg-config
file. It adds -DMODPLUG_STATIC to CFlags, so that when libmod_plugin is
building it will have the correct symbol names.

However, there is also a bug in the build system that needs to be fixed for
this to work. The configure script sets a CXXFLAGS_mod containing the
output of pkg-config for libmodplug, but not CFLAGS_mod. Additionally, the
Makefile.ac for libmod_plugin sets CXXFLAGS when in fact the relevant files
(mod.c) are plain C. Autotools therefore ignores these CXXFLAGS when
generating a makefile.

The solution is to add a macro to configure.ac to set CFLAGS_mod. This then
needs to be used in modules/demux/Makefile.am to populate
libmod_plugin_la_CFLAGS instead of libmod_plugin_la_CXXFLAGS (which gets
ignored). This patch contains these changes.
 configure.ac                                   | 1 +
 contrib/src/modplug/modplug-win32-static.patch | 9 +++++++++
 contrib/src/modplug/rules.mak                  | 1 +
 modules/demux/Makefile.am                      | 2 +-
 4 files changed, 12 insertions(+), 1 deletion(-)
 create mode 100644 contrib/src/modplug/modplug-win32-static.patch

diff --git a/configure.ac b/configure.ac
index 2611a11..a754c2d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2070,6 +2070,7 @@ if test "${enable_mod}" != "no" ; then
     PKG_CHECK_MODULES(LIBMODPLUG, [libmodplug >= 0.8.4 libmodplug != 0.8.8], [
+          VLC_ADD_CFLAGS([mod],[$LIBMODPLUG_CFLAGS]) #modules/demux/mod.c needs CFLAGS_mod, not CXXFLAGS_mod
        AS_IF([test -n "${enable_mod}"],
diff --git a/contrib/src/modplug/modplug-win32-static.patch b/contrib/src/modplug/modplug-win32-static.patch
new file mode 100644
index 0000000..4cd93a4
--- /dev/null
+++ b/contrib/src/modplug/modplug-win32-static.patch
@@ -0,0 +1,9 @@
+diff -rupN libmodplug-old/libmodplug.pc.in libmodplug-new/libmodplug.pc.in
+--- libmodplug-old/libmodplug.pc.in	2013-08-23 09:55:58.000000000 +1000
++++ libmodplug-new/libmodplug.pc.in	2014-06-12 20:59:17.705886752 +1000
+@@ -9,4 +9,4 @@ Version: @VERSION@
+ Requires: 
+ Libs: -L${libdir} -lmodplug 
+ Libs.private: -lstdc++ -lm
+-Cflags: -I${includedir}
++Cflags: -I${includedir} -DMODPLUG_STATIC
diff --git a/contrib/src/modplug/rules.mak b/contrib/src/modplug/rules.mak
index 8ac2484..a82a4d3 100644
--- a/contrib/src/modplug/rules.mak
+++ b/contrib/src/modplug/rules.mak
@@ -15,6 +15,7 @@ $(TARBALLS)/libmodplug-$(MODPLUG_VERSION).tar.gz:
 libmodplug: libmodplug-$(MODPLUG_VERSION).tar.gz .sum-modplug
+	$(APPLY) $(SRC)/modplug/modplug-win32-static.patch
 	$(call pkg_static,"libmodplug.pc.in")
diff --git a/modules/demux/Makefile.am b/modules/demux/Makefile.am
index c19caf1..75f5b52 100644
--- a/modules/demux/Makefile.am
+++ b/modules/demux/Makefile.am
@@ -41,7 +41,7 @@ libps_plugin_la_SOURCES = demux/ps.c demux/ps.h
 demux_LTLIBRARIES += libps_plugin.la
 libmod_plugin_la_SOURCES = demux/mod.c
-libmod_plugin_la_CXXFLAGS = $(AM_CXXFLAGS) $(CXXFLAGS_mod)
+libmod_plugin_la_CFLAGS = $(AM_CFLAGS) $(CFLAGS_mod)
 libmod_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(demuxdir)'
 libmod_plugin_la_LIBADD = $(LIBS_mod)
 EXTRA_LTLIBRARIES += libmod_plugin.la

More information about the vlc-devel mailing list