1
我想用C编写一个使用Zend框架的.so PHP扩展。通过独立扩展,一切正常。但是,如果我尝试在我的分机使用其他一些动态链接库,我得到以下错误:如何在Zend PHP扩展中连接外部C/C++库
PHP Warning: dl(): Unable to load dynamic library '/usr/lib/php5/20121212/test.so' - /usr/lib/php5/20121212/test.so: undefined symbol: _Z5hellov in /var/www/test.php on line 2
PHP Fatal error: Call to undefined function my_function() in /var/www/test.php on line 3
我已经编译libhello.so并复制到同一个目录/ usr/lib目录/ PHP5/20121212/ 如何从test.so模块使用它?
这里是源代码:
test.c的:
#include "php.h"
#include "hello.h"
ZEND_FUNCTION(my_function);
ZEND_FUNCTION(Hello);
zend_function_entry firstmod_functions[] =
{
ZEND_FE(my_function, NULL)
ZEND_FE(Hello, NULL)
{NULL, NULL, NULL}
};
zend_module_entry firstmod_module_entry =
{
STANDARD_MODULE_HEADER,
"First Module",
firstmod_functions,
NULL,
NULL,
NULL,
NULL,
NULL,
NO_VERSION_YET,
STANDARD_MODULE_PROPERTIES
};
ZEND_GET_MODULE(firstmod)
ZEND_FUNCTION(my_function)
{
char *str; int str_len;
long l;
if(ZEND_NUM_ARGS() != 2) WRONG_PARAM_COUNT;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sl",
&str, &str_len, &l) == FAILURE) {
return;
}
zend_printf("%s \r\n", str);
zend_printf("%ld \r\n", l);
RETURN_LONG(1);
}
ZEND_FUNCTION (Hello) {
hello();
}
hello.h:
#include <stdio.h>
void hello();
的hello.c:
#include "hello.h"
void hello() {
printf("%s\n", "Hello, world!");
}
test.php的:
<?php
dl("test.so");
my_function("123",12);
Hello();
?>