Custom PHP extension - Invalid library (maybe not a PHP library)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi all!

I'm interested in creating a custom PHP extension. I have found
several so called tutorials,
but the code examples they contain do not work for me.

Let's stick to this site:
http://devzone.zend.com/303/extension-writing-part-i-introduction-to-php-and-zend/
Basing on it I have following sources:


######################### config.m4:
PHP_ARG_ENABLE(hello2,whether to enable hello2 support,
[  --enable-hello2            Enable hello2 support])

if test "$PHP_HELLO2" = "yes"; then
 AC_DEFINE(HAVE_HELLO2,1,[Whether you want hello2 support])
 PHP_NEW_EXTENSION(hello2, php_hello2.c, $ext_shared)
fi
#########################


######################### php_hello2.h:
#ifndef PHP_HELLO2_H
#define PHP_HELLO2_H 1
#define PHP_HELLO_WORLD_VERSION "1.0"
#define PHP_HELLO_WORLD_EXTNAME "hello2"

PHP_FUNCTION(hello_world);

extern zend_module_entry hello2_module_entry;
#define phpext_hello2_ptr &hello2_module_entry

#endif
#########################


######################### php_hello2.c:
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "php.h"
#include "php_hello2.h"

static function_entry hello2_functions[] = {
   PHP_FE(hello_world, NULL)
   {NULL, NULL, NULL}
};

zend_module_entry hello2_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
   STANDARD_MODULE_HEADER,
#endif
   PHP_HELLO_WORLD_EXTNAME,
   hello2_functions,
   NULL, NULL, NULL, NULL, NULL,
#if ZEND_MODULE_API_NO >= 20010901
   PHP_HELLO_WORLD_VERSION,
#endif
   STANDARD_MODULE_PROPERTIES
};

#ifdef COMPILE_DL_HELLO2
ZEND_GET_MODULE(hello2)
#endif

PHP_FUNCTION(hello_world)
{
   RETURN_STRING("Hello World", 1);
}
#########################

The code compiles well with these commands:
$ ./configure --enable-hello2
$ make -j5
# make install

But after I execute the command:
$ php5 -d"extension=hello2.so" -v
I get the following output.

PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library)
'hello2.so' in Unknown on line 0

What I am missing here? Can someone help me?
Thanks in advance.

Kind Regards,
Sławomir

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux