我正在编写一个PHP5扩展名,而我可以在C中编写它,这将更容易使用C并利用STL和Boost。
麻烦的是,tutorials我看过只处理C,而我正在寻找使用C的基本例子
这是我迄今为止所尝试过的
config.m4中
[ --enable-hello Enable Hello World support])
if test "$PHP_HELLO" = "yes"; then
AC_DEFINE(HAVE_HELLO, 1, [Whether you have Hello World])
PHP_NEW_EXTENSION(hello, hello.cpp, $ext_shared)
fi
php_hello.h
注意我尝试声明PHP接口的位为extern“C”
#ifndef PHP_HELLO_H
#define PHP_HELLO_H 1
extern "C" {
#define PHP_HELLO_WORLD_VERSION "1.0"
#define PHP_HELLO_WORLD_EXTNAME "hello"
PHP_FUNCTION(hello_world);
extern zend_module_entry hello_module_entry;
#define phpext_hello_ptr &hello_module_entry
}
#endif
HELLO.CPP
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_hello.h"
static function_entry hello_functions[] = {
PHP_FE(hello_world, NULL)
{NULL, NULL, NULL}
};
zend_module_entry hello_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
STANDARD_MODULE_HEADER,
#endif
PHP_HELLO_WORLD_EXTNAME,
hello_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
#if ZEND_MODULE_API_NO >= 20010901
PHP_HELLO_WORLD_VERSION,
#endif
STANDARD_MODULE_PROPERTIES
};
#ifdef COMPILE_DL_HELLO
ZEND_GET_MODULE(hello)
#endif
PHP_FUNCTION(hello_world)
{
RETURN_STRING("Hello World", 1);
}
….这里是我的构建错误:
如果我phpize,配置和做这个,我得到以下(为了清楚重新格式化)
$ make
/bin/bash /home/paul/php5/php-5.2.8/ext/hello2/libtool
--mode=compile
-I.
-I/home/paul/php5/php-5.2.8/ext/hello2 -DPHP_ATOM_INC
-I/home/paul/php5/php-5.2.8/ext/hello2/include
-I/home/paul/php5/php-5.2.8/ext/hello2/main
-I/home/paul/php5/php-5.2.8/ext/hello2
-I/usr/local/include/php
-I/usr/local/include/php/main
-I/usr/local/include/php/TSRM
-I/usr/local/include/php/Zend
-I/usr/local/include/php/ext
-I/usr/local/include/php/ext/date/lib
-DHAVE_CONFIG_H
-c /home/paul/php5/php-5.2.8/ext/hello2/hello.cpp
-o hello.lo
libtool: compile: unrecognized option `-I.'
libtool: compile: Try `libtool --help' for more information.
make: *** [hello.lo] Error 1
我怀疑为了创建一个工作的makefile,我需要更多的工作去做config.m4,但是我对于GCC工具链来说很新鲜。
如果它有帮助,我只针对php 5.2.6,只有在Linux(特别是Ubuntu 8.04)上。我的构建环境正在使用Ubuntu 8.10,使用gcc 4.3.2
指针感谢!