在 Ubuntu 上编译 PHP 扩展库(Karmic Koala)

发布于 2024-08-21 19:25:13 字数 2848 浏览 10 评论 0原文

不久前,我在 XP 平台上编译了一些 PHP 扩展库(C/C++ 语言)。我现在已将源代码移至我的 Ubuntu 机器上,并希望构建在我的 Linux 机器上使用的库。

然而,我遇到了许多障碍:

  1. 我无法找到 phpize(即使在安装了 php5dev 软件包之后)
  2. 我无法找到 ext_skel 来生成骨架脚本/文件

[编辑]

感谢 Pascal Martin 和< a href="https://stackoverflow.com/questions/1250412/how-do-i-build-my-first-php-extension-in-c-on-linux-gcc" title="这个问题">这个问题,我已经成功构建并测试了我的一个较小的库。我只想在继续其他库之前仔细检查 .m4 文件的内容(因为我不熟悉该格式)。

这是自动生成的 .m4 文件的内容 - 任何熟悉该格式的人都可以解释一下它的含义吗 - 这样我就可以双重确定我已取消注释该文件的正确部分。

下面显示了 config.m4 文件的内容及其所有血淋淋的细节:

dnl $Id$
dnl config.m4 for extension tanlib

dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.

dnl If your extension references something external, use with:

dnl PHP_ARG_WITH(tanlib, for tanlib support,
dnl Make sure that the comment is aligned:
dnl [  --with-tanlib             Include tanlib support])

dnl Otherwise use enable:

PHP_ARG_ENABLE(tanlib, whether to enable tanlib support,
dnl Make sure that the comment is aligned:
[  --enable-tanlib           Enable tanlib support])

if test "$PHP_TANLIB" != "no"; then
  dnl Write more examples of tests here...

  dnl # --with-tanlib -> check with-path
  dnl SEARCH_PATH="/usr/local /usr"     # you might want to change this
  dnl SEARCH_FOR="/include/tanlib.h"  # you most likely want to change this
  dnl if test -r $PHP_TANLIB/$SEARCH_FOR; then # path given as parameter
  dnl   TANLIB_DIR=$PHP_TANLIB
  dnl else # search default path list
  dnl   AC_MSG_CHECKING([for tanlib files in default path])
  dnl   for i in $SEARCH_PATH ; do
  dnl     if test -r $i/$SEARCH_FOR; then
  dnl       TANLIB_DIR=$i
  dnl       AC_MSG_RESULT(found in $i)
  dnl     fi
  dnl   done
  dnl fi
  dnl
  dnl if test -z "$TANLIB_DIR"; then
  dnl   AC_MSG_RESULT([not found])
  dnl   AC_MSG_ERROR([Please reinstall the tanlib distribution])
  dnl fi

  dnl # --with-tanlib -> add include path
  dnl PHP_ADD_INCLUDE($TANLIB_DIR/include)

  dnl # --with-tanlib -> check for lib and symbol presence
  dnl LIBNAME=tanlib # you may want to change this
  dnl LIBSYMBOL=tanlib # you most likely want to change this

  dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
  dnl [
  dnl   PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TANLIB_DIR/lib, TANLIB_SHARED_LIBADD)
  AC_DEFINE(HAVE_TANLIBLIB,1,[ Whether you have tanlib])
  dnl ],[
  dnl   AC_MSG_ERROR([wrong tanlib lib version or lib not found])
  dnl ],[
  dnl   -L$TANLIB_DIR/lib -lm -ldl
  dnl ])
  dnl
  dnl PHP_SUBST(TANLIB_SHARED_LIBADD)

  PHP_NEW_EXTENSION(tanlib, tanlib.c, $ext_shared)
fi 

有人理解上面的内容吗?

顺便说一句,上面的 config.m4 文件是使用 Autoconf 2.50 生成的(我也刚刚看到文档 这里,我正在慢慢消化它。

I compiled some PHP extention libs (in C/C++) a while back, on my XP platform. I have now moved the sources to my Ubuntu box, and want to build the libs for use on my Linux box.

However, I have come accross a number of obstacles:

  1. I cant locate phpize (even after installing the php5dev package)
  2. I cant find ext_skel to generate the skeleton script/files

[Edit]

Thanks to Pascal Martin and this question, I have managed to build and test one of my smaller libraries. I just want to double check the contents of my .m4 file (since I am not familiar with the format), before I go ahead with the other libraries.

This is the content of the autogenerated .m4 file - is anyone familiar with the format, and can they explain what it means - this is so that I can be doubly sure that I have uncommented the correct sections of the file.

The contents of the config.m4 file are displayed below in all their gory detail:

dnl $Id$
dnl config.m4 for extension tanlib

dnl Comments in this file start with the string 'dnl'.
dnl Remove where necessary. This file will not work
dnl without editing.

dnl If your extension references something external, use with:

dnl PHP_ARG_WITH(tanlib, for tanlib support,
dnl Make sure that the comment is aligned:
dnl [  --with-tanlib             Include tanlib support])

dnl Otherwise use enable:

PHP_ARG_ENABLE(tanlib, whether to enable tanlib support,
dnl Make sure that the comment is aligned:
[  --enable-tanlib           Enable tanlib support])

if test "$PHP_TANLIB" != "no"; then
  dnl Write more examples of tests here...

  dnl # --with-tanlib -> check with-path
  dnl SEARCH_PATH="/usr/local /usr"     # you might want to change this
  dnl SEARCH_FOR="/include/tanlib.h"  # you most likely want to change this
  dnl if test -r $PHP_TANLIB/$SEARCH_FOR; then # path given as parameter
  dnl   TANLIB_DIR=$PHP_TANLIB
  dnl else # search default path list
  dnl   AC_MSG_CHECKING([for tanlib files in default path])
  dnl   for i in $SEARCH_PATH ; do
  dnl     if test -r $i/$SEARCH_FOR; then
  dnl       TANLIB_DIR=$i
  dnl       AC_MSG_RESULT(found in $i)
  dnl     fi
  dnl   done
  dnl fi
  dnl
  dnl if test -z "$TANLIB_DIR"; then
  dnl   AC_MSG_RESULT([not found])
  dnl   AC_MSG_ERROR([Please reinstall the tanlib distribution])
  dnl fi

  dnl # --with-tanlib -> add include path
  dnl PHP_ADD_INCLUDE($TANLIB_DIR/include)

  dnl # --with-tanlib -> check for lib and symbol presence
  dnl LIBNAME=tanlib # you may want to change this
  dnl LIBSYMBOL=tanlib # you most likely want to change this

  dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL,
  dnl [
  dnl   PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $TANLIB_DIR/lib, TANLIB_SHARED_LIBADD)
  AC_DEFINE(HAVE_TANLIBLIB,1,[ Whether you have tanlib])
  dnl ],[
  dnl   AC_MSG_ERROR([wrong tanlib lib version or lib not found])
  dnl ],[
  dnl   -L$TANLIB_DIR/lib -lm -ldl
  dnl ])
  dnl
  dnl PHP_SUBST(TANLIB_SHARED_LIBADD)

  PHP_NEW_EXTENSION(tanlib, tanlib.c, $ext_shared)
fi 

Does anyone grok the above?

BTW, the above config.m4 file was generated using Autoconf 2.50 (I have also just seen the documentation here and am slowly digesting it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夢归不見 2024-08-28 19:25:13

在我的 Ubuntu 计算机上,phpize 位于:

$ which phpize
/usr/bin/phpize

ext_skel 应该位于 PHP 源代码的“ext”目录中,您可以通过 SVN 获取该目录。

这是ext目录:http://svn.php.net/viewvc/php/php-src/trunk/ext/

并且可以查看脚本内容

README.EXT_SKEL 就位于 trunk/ 下方。

如果您是 git 用户,github 上有一个 SVN 镜像: http://github.com /php/

On my Ubuntu computer, phpize is in :

$ which phpize
/usr/bin/phpize

And ext_skel should be in the "ext" directory, in the PHP sources, which you can get by SVN.

Here's the ext directory : http://svn.php.net/viewvc/php/php-src/trunk/ext/

And you can view the content of the script here.

The README.EXT_SKEL is just under trunk/.

If you're more of a git user, there is a mirror of the SVN on github : http://github.com/php/

囚我心虐我身 2024-08-28 19:25:13

为了回答您的后续问题,dnl.m4 文件中的行注释标记,因此这些行当前没有执行任何操作。这可能没问题,因为它们大多仅在您使用外部库时才相关(并且按照惯例使用 --with-myextension 配置选项而不是 --enable-myextension< /代码>)。

因此,上述文件(截至修订版 3)相当于:

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

if test "$PHP_TANLIB" != "no"; then
  AC_DEFINE(HAVE_TANLIBLIB,1,[ Whether you have tanlib])  
  PHP_NEW_EXTENSION(tanlib, tanlib.c, $ext_shared)
fi 

因此,如果您在此目录中执行以下操作,它应该可以工作(我认为,我没有合适的 Linux 机器来检查此操作):

phpize
./configure --enable-tanlib
make
make install

最后, make确保在 /etc/php5/conf.d 中启用了该扩展。

请记住,您需要重新启动 apache (sudo /etc/init.d/apache2 restart) 才能使所有扩展更改生效。

To answer your followup question, dnl is the line comment marker in .m4 files, so those lines aren't doing anything currently. That's probably OK, since they're mostly only relevant if you're using an external library (and by convention using the --with-myextension configure option rather than --enable-myextension).

The above file (as of revision 3) is therefore equivalent to:

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

if test "$PHP_TANLIB" != "no"; then
  AC_DEFINE(HAVE_TANLIBLIB,1,[ Whether you have tanlib])  
  PHP_NEW_EXTENSION(tanlib, tanlib.c, $ext_shared)
fi 

So if you do the following in this directory, it should work (I think, I don't have a suitable Linux machine to hand to check this):

phpize
./configure --enable-tanlib
make
make install

Finally, make sure that the extension is enabled in /etc/php5/conf.d.

Remember you'll need to restart apache (sudo /etc/init.d/apache2 restart) to pick up any extension changes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文