Skip to content

Instantly share code, notes, and snippets.

@auroraeosrose
Created August 24, 2012 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auroraeosrose/3452993 to your computer and use it in GitHub Desktop.
Save auroraeosrose/3452993 to your computer and use it in GitHub Desktop.
support libxml PHP extension shared and against shared dll on windows
// $Id$
// vim:ft=javascript
ARG_WITH("libxml", "LibXML support", "yes");
ARG_WITH("libxmlshared", "LibXML support", "no");
if (PHP_LIBXMLSHARED == "yes") {
PHP_LIBXML = PHP_LIBXMLSHARED;
PHP_LIBXML_SHARED = PHP_LIBXMLSHARED_SHARED;
if (CHECK_LIB("libxml2.lib", "libxml") &&
CHECK_LIB("libiconv.lib;iconv.lib", "libxml") &&
CHECK_HEADER_ADD_INCLUDE("libxml/parser.h", "CFLAGS_LIBXML") &&
ADD_EXTENSION_DEP('libxml', 'iconv')) {
EXTENSION("libxml", "libxml.c", PHP_LIBXML_SHARED);
AC_DEFINE("HAVE_LIBXML", 1, "LibXML support");
ADD_FLAG("CFLAGS_LIBXML", "/D HAVE_WIN32_THREADS ");
PHP_INSTALL_HEADERS("ext/libxml/", "php_libxml.h");
} else {
WARNING("libxml support can't be enabled, iconv or libxml are missing")
PHP_LIBXML = "no"
}
} else if (PHP_LIBXML == "yes") {
if (CHECK_LIB("libxml2_a_dll.lib;libxml2_a.lib", "libxml") &&
CHECK_LIB("libiconv_a.lib;iconv_a.lib;libiconv.lib;iconv.lib", "libxml") &&
CHECK_HEADER_ADD_INCLUDE("libxml/parser.h", "CFLAGS_LIBXML") &&
ADD_EXTENSION_DEP('libxml', 'iconv')) {
EXTENSION("libxml", "libxml.c", false /* never shared */);
AC_DEFINE("HAVE_LIBXML", 1, "LibXML support");
ADD_FLAG("CFLAGS_LIBXML", "/D LIBXML_STATIC /D LIBXML_STATIC_FOR_DLL /D HAVE_WIN32_THREADS ");
if (!PHP_LIBXML_SHARED) {
ADD_DEF_FILE("ext\\libxml\\php_libxml2.def");
}
PHP_INSTALL_HEADERS("ext/libxml/", "php_libxml.h");
} else {
WARNING("libxml support can't be enabled, iconv or libxml are missing")
PHP_LIBXML = "no"
}
}
@nono303
Copy link

nono303 commented Feb 23, 2022

Hi @auroraeosrose
Thx for this patch!
Actually on PHP8.1 I'm facing this error with --with-libxmlshared and libxml2.lib (all works with --with-libxml and libxml2_a_dll.lib)

   Creating library C:\sdk\src\php-sdk\phpmaster\vs17\x64\build\Release\php8.lib and object C:\sdk\src\php-sdk\phpmaster\vs17\x64\build\Release\php8.exp
dllmain.obj : error LNK2001: unresolved external symbol xmlDllMain

Have you encounter this issue?
What I tried to fix it without success:

  • I changed header for shared from libxml/parser.h to libxml/threads.h
  • Change in libxml/threads.h
    • force XMLPUBFUN for xmlDllMain
    • add __declspec(dllexport) for __imp_xmlDllMain
  • build shared dll and imp lib with cflag LIBXML_STATIC_FOR_DLL
  • check with dumpbin /EXPORTS that xmlDllMain is well exposed on libxml2.lib / libxml2.dll
  • Have a look at win32/dllmain.c code...

Here are:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment