gpt4 book ai didi

使用 libtidy 的 PHP 扩展编译,但不加载

转载 作者:IT王子 更新时间:2023-10-29 00:22:31 31 4
gpt4 key购买 nike

我用 C++ 编写了一个使用 libtidy 的扩展,当我编译 PHP --with-tidy 时,它在 PHP 下完美运行。

但是,如果扩展在 vanilla PHP 上运行会很好。当我尝试使用扩展程序时,我得到类似的信息:

PHP Warning:     PHP Startup:     Unable to load dynamic library 'extension.so':       undefined symbol: tidyCleanAndRepair in Unknown on line 0

and the extension is not loaded.

Obviously, the official tidy extension works fine. I have the relevant libtidy development packages installed on the system, and it compiles+links without a problem. I have tried to look through the code for the tidy extension, but it is a huge mass of macros - copying pieces at random felt like cargo code.

Besides linking to the library with PHP_ADD_LIBRARY_WITH_PATH(tidy, $TIDY_LIBDIR, TIDY_SHARED_LIBADD), Is there a PHP extension or C statement that fixes this error?

Thanks in advance!!

EDIT: here is the entire config.m4 file:

dnl config.m4 for extension htmlparser

PHP_ARG_ENABLE(htmlparse, whether to enable htmlparser support,
[ --enable-htmlparser Enable htmlparser support])

if test "$PHP_HTMLPARSER" != "no"; then


if test -r $PHP_LIBXML2/lib/libxml2.a; then
LIBXML2_DIR=$PHP_LIBXML2
else
AC_MSG_CHECKING(for libxml2 in default path)
for i in /usr/local /usr; do
if test -r $i/lib/libxml2.a; then
LIBXML2_DIR=$i
AC_MSG_RESULT(found in $i)
fi
done
fi

if test -z "$LIBXML2_DIR"; then
AC_MSG_RESULT(not found)
AC_MSG_ERROR(Please reinstall the libxml2 distribution - libxml2.h should
be in <libxml2-dir>/include and libxml2.a should be in <libxml2- dir>/lib)
fi
PHP_ADD_INCLUDE($LIBXML2_DIR/include/libxml2)
PHP_ADD_LIBRARY_WITH_PATH(libxml2, $LIBXML2_DIR/lib, LIBXML2_SHARED_LIBADD)

AC_MSG_CHECKING(for boost in default path)
for i in /usr/local /usr; do
if test -r $i/include/boost; then
BOOST_DIR=$i
AC_MSG_RESULT(found in $i)
fi
done

if test -z "$BOOST_DIR"; then
AC_MSG_RESULT(not found)
AC_MSG_ERROR(Please reinstall the boost distribution!!!)
fi
PHP_ADD_INCLUDE($BOOST_DIR/include/boost/)


TIDY_SEARCH_DIRS="/usr/local /usr"
for i in $TIDY_SEARCH_DIRS; do
if test -f $i/include/tidy/tidy.h; then
TIDY_DIR=$i
TIDY_INCDIR=$i/include/tidy
elif test -f $i/include/tidy.h; then
TIDY_DIR=$i
TIDY_INCDIR=$i/include
fi
done


if test -z "$TIDY_DIR"; then
AC_MSG_ERROR(Cannot find libtidy)
fi

TIDY_LIBDIR=$TIDY_DIR/lib

PHP_ADD_INCLUDE($TIDY_INCDIR)
PHP_ADD_LIBRARY_WITH_PATH(tidy, $TIDY_LIBDIR, TIDY_SHARED_LIBADD)

PHP_CHECK_LIBRARY(tidy,tidyOptGetDoc,
[
AC_DEFINE(HAVE_TIDYOPTGETDOC,1,[ ])
],[],[])

AC_DEFINE(HAVE_HTMLPARSER, 1, [Whether you want htmlparser support])
PHP_SUBST(HTMLPARSER_SHARED_LIBADD)
PHP_ADD_LIBRARY_WITH_PATH(stdc++, 1, HTMLPARSER_SHARED_LIBADD)
PHP_REQUIRE_CXX()
PHP_NEW_EXTENSION(htmlparser, php_htmlparser.cpp parsehtml.cpp StringBuilder.cpp, $ext_shared)
fi

最佳答案

您是否使用与 vanilla php 相同的 php 版本编译您的扩展?你应该使用相同版本的 php 源代码。此外,请确保在 php.ini 文件中,您在扩展之前加载了“libtidy”扩展。

关于使用 libtidy 的 PHP 扩展编译,但不加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2981702/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com