1,创建一个扩展
./ext_skel --extname=libs
2,配置(config.m4)
SEARCH_PATH="/usr/local /usr" #lib搜索的目录
SEARCH_FOR="/include/curl/curl.h" #lib头文件的路径
if test -r $PHP_LIBS/$SEARCH_FOR; then
LIBS_DIR=$PHP_LIBS
else # search default path list
AC_MSG_CHECKING([for libs files in default path])
for i in $SEARCH_PATH ; do
if test -r $i/$SEARCH_FOR; then
LIBS_DIR=$i #搜索到的lib的路径
AC_MSG_RESULT(found in $i)
fi
done
fi
/*验证lib是否存在*/
if test -z "$LIBS_DIR"; then
AC_MSG_RESULT([not found])
AC_MSG_ERROR([Please reinstall the libs distribution])
fi
/*编译的时候添加lib的include目录, -I/usr/include*/
PHP_ADD_INCLUDE($LIBS_DIR/include)
LIBNAME=curl #lib名称
LIBSYMBOL=curl_version #lib的一个函数,用来PHP_CHECK_LIBRARY验证lib
/*验证lib*/
PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
[
PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $LIBS_DIR/$PHP_LIBDIR, LIBS_SHARED_LIBADD) #编译的时候链接lib, -llibcurl
AC_DEFINE(HAVE_LIBSLIB,1,[ ])
],[
AC_MSG_ERROR([wrong libs lib version or lib not found])
],[
-L$LIBS_DIR/$PHP_LIBDIR -lm
])
PHP_SUBST(LIBS_SHARED_LIBADD)