Index: Makefile =================================================================== --- Makefile (revision 9126) +++ Makefile (working copy) @@ -33,7 +33,12 @@ # LDLIBS # ARFLAGS # +# CXXSTDLIB_PCLIBSPRIVATE C++ standard library (or libraries) required for +# static linking. This will be put in the pkg-config file +# libopenmpt.pc Libs.private field and used for nothing else. # +# +# # Build flags (provide on each `make` invocation) (defaults are shown): # # DYNLINK=1 Dynamically link examples and openmpt123 against libopenmpt @@ -355,6 +360,9 @@ endif +PC_LIBS_PRIVATE := +PC_LIBS_PRIVATE += $(CXXSTDLIB_PCLIBSPRIVATE) + ifeq ($(HACK_ARCHIVE_SUPPORT),1) NO_ZLIB:=1 endif @@ -960,7 +968,7 @@ $(VERYSILENT)echo 'Version: $(DIST_LIBOPENMPT_VERSION)' >> $@.tmp $(VERYSILENT)echo 'Requires.private: $(PC_REQUIRES_ZLIB) $(PC_REQUIRES_MPG123) $(PC_REQUIRES_OGG) $(PC_REQUIRES_VORBIS) $(PC_REQUIRES_VORBISFILE)' >> $@.tmp $(VERYSILENT)echo 'Libs: -L$${libdir} -lopenmpt' >> $@.tmp - $(VERYSILENT)echo 'Libs.private: ' >> $@.tmp + $(VERYSILENT)echo 'Libs.private: $(PC_LIBS_PRIVATE)' >> $@.tmp $(VERYSILENT)echo 'Cflags: -I$${includedir}' >> $@.tmp $(VERYSILENT)mv $@.tmp $@ Index: build/autotools/configure.ac =================================================================== --- build/autotools/configure.ac (revision 9126) +++ build/autotools/configure.ac (working copy) @@ -33,6 +33,9 @@ AC_DEFINE([MPT_PACKAGE], [!!MPT_PACKAGE!!], [is package]) +AC_ARG_VAR(CXXSTDLIB_PCLIBSPRIVATE, [C++ standard library (or libraries) required for static linking. This will be put in the pkg-config file libopenmpt.pc Libs.private field and used for nothing else.]) + + AC_CANONICAL_HOST case $host_os in mingw32*) @@ -126,7 +129,7 @@ LIBOPENMPT_REQUIRES_PRIVATE="$ZLIB_PKG $MPG123_PKG $OGG_PKG $VORBIS_PKG $VORBISFILE_PKG" -LIBOPENMPT_LIBS_PRIVATE="" +LIBOPENMPT_LIBS_PRIVATE="$CXXSTDLIB_PCLIBSPRIVATE" AC_SUBST([LIBOPENMPT_REQUIRES_PRIVATE]) AC_SUBST([LIBOPENMPT_LIBS_PRIVATE]) Index: libopenmpt/dox/changelog.md =================================================================== --- libopenmpt/dox/changelog.md (revision 9126) +++ libopenmpt/dox/changelog.md (working copy) @@ -7,6 +7,12 @@ ### libopenmpt 0.4.0-pre + * [**New**] Autotools `configure` and plain `Makefile` now honor the variable + `CXXSTDLIB_PCLIBSPRIVATE` which serves the sole purpose of listing the + standard library (or libraries) required for static linking. The contents of + this variable will be put in `libopenmpt.pc` `Libs.private` and used for + nothing else. See \ref libopenmpt_c_staticlinking . + * [**Bug**] libopenmpt did not build on Android NDK 15c (and possibly other versions between 12b and 15c as well). Index: libopenmpt/dox/packaging.md =================================================================== --- libopenmpt/dox/packaging.md (revision 9126) +++ libopenmpt/dox/packaging.md (working copy) @@ -18,6 +18,9 @@ transformation if required. * Use the autotools source package. * Use the default set of dependencies required by the autotools package. + * Read \ref libopenmpt_c_staticlinking and thus possibly pass + `CXXSTDLIB_PCLIBSPRIVATE` variable to `configure` if appropriate and/or + desired. * Run the test suite in your build process. * Send any build system improvement patches upstream. * Do not include the libmodplug emulation layer in the default libopenmpt Index: libopenmpt/libopenmpt.h =================================================================== --- libopenmpt/libopenmpt.h (revision 9126) +++ libopenmpt/libopenmpt.h (working copy) @@ -111,6 +111,37 @@ * - Consecutive accesses can happen from different threads. * - Different objects can be accessed concurrently from different threads. * + * \section libopenmpt_c_staticlinking Statically linking to libopenmpt + * + * libopenmpt is implemented in C++. This imlies that linking to libopenmpt + * statically requires linking to the C++ runtime and standard library. The + * **highly preferred and recommended** way to do this is by using the C++ + * compiler instead of the platform linker to do the linking. This will do all + * necessary things that are C++ specific (in particular, it will pull in the + * appropriate runtime and/or library). If for whatever reason it is not + * possible to use the C++ compiler for statically linking against libopenmpt, + * the libopenmpt build system can list the required libraries in the pkg-config + * file `libopenmpt.pc`. However, there is no reliable way to determine the name + * of the required library or libraries from within the build system. The + * libopenmpt autotools `configure` and plain `Makefile` honor the custom + * variable `CXXSTDLIB_PCLIBSPRIVATE` which serves the sole purpose of listing + * the standard library (or libraries) required for static linking. The contents + * of this variable will be put in `libopenmpt.pc` `Libs.private` and used for + * nothing else. + * + * This problem is inherent to libraries implemented in C++ that can also be used + * without a C++ compiler. Other libraries try to solve that by listing + * `-lstdc++` unconditionally in `Libs.private`. However, that will break + * platforms that use a different C++ standard library (in particular FreeBSD). + * + * See https://lists.freedesktop.org/archives/pkg-config/2016-August/001055.html . + * + * Dymically linking to libopenmpt does not require anything special and will + * work as usual (and exactly as done for libraries implemented in C). + * + * Note: This section does not apply when using Microsoft Visual Studio or + * Andriod NDK ndk-build build systems. + * * \section libopenmpt_c_detailed Detailed documentation * * \ref libopenmpt_c