[xml] build with win32 host broken if --disable-shared is given

If a windows target is used (in my case, I'm crosscompiling from debian
linux to mingw32) and --disable-shared is given (in order to only build
a static library), the resulting library cannot be used (and as a result
the build fails when making xmllint (or most other executables)).

The cause is xmlexports.h - it assumes that LIBXML_STATIC will be
defined if the user wants to link with the static library, otherwise it
marks some functions and/or variables as DLL exports/imports.  While
this is reasonable behaviour if both shared and static versions of the
library are built, it is not reasonable in the case only a static
library is built.  In this case, most programs that use libxml2
(including xmllint, xmlcatalog and most, but not all examples) will fail
to link, because the linker looks for the dllimport version of

This is easy enough to fix, however - the configure script could easily
detect that shared libraries are disabled and add -DLIBXML_STATIC to
CFLAGS and XML_CFLAGS.  This would also cause xml2-config to include
that definition in its --cflags output, and all well-behaved client
programs would automagically get the correct settings.

Example (modified from an existing $host check):

case ${host} in
        XML_LIBDIR="${XML_LIBDIR} -R${libdir}"
    *-*-mingw* | *-*-cygwin* | *-*-msvc* )
        # If the host is Windows, and shared libraries are disabled, we
        # need to add -DLIBXML_STATIC to CFLAGS in order for linking to
        # work properly (without it, xmlexports.h would force the use of
        # DLL imports, which obviously aren't present in a static
        # library).
        if test "x$enable_shared" = "xno"; then

(note: the above case may not yet match all relevant host triplets; both
CFLAGS and XML_CFLAGS need to be set to get both the desired xml2-config
and a working link of xmllint/xmlcatalog/...)

On a related note (not included in the original bugzilla report),
on a windows target -lws2_32 is needed when linking but this library
specification does not make it into xml2-config.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]