Board index   FAQ   Search  
Register  Login
Board index PHP PEAR and PECL

Building PHP extensions on Windows

Do you have questions regarding Pecl or Pear? ask here!

Moderators: macek, egami, gesf

Building PHP extensions on Windows

Postby byte-aligned » Thu Aug 18, 2005 2:18 pm

Hi all, I´m trying to start developing PHP extensions on Windows. I´m using Visual Studio .NET 2003 and I have been following some tutorials found in Internet, I´m very close to compile a test extension, but still need to fix something, hope you can help me :)

The tutorial is this: hxxp://www.osix.net/modules/article/?id=585

At this point I have prepared all the includes and paths, I have been able to build the dll but nothing is shown about my test extension in phpinfo(), also I cant use test functions defined on my test extension. I have added the extension to extensions directory in PHP and added "extension=php_extend.dll" on php.ini.

After building on VS I receive 7 warnings and 0 errors, the tutorial says some warnings are not important.

Source code follows:

php_extend.h
Code: Select all
#define ZEND_WIN32
#define PHP_WIN32

#define ZEND_DEBUG 0
#define COMPILE_DL_EXTEND 1
#define ZTS 1
#include "php.h"



php_extend.c
Code: Select all
#include "php_extend.h";

ZEND_FUNCTION(myfirstfunc);
ZEND_FUNCTION(myfirstfunc2);

PHP_MINFO_FUNCTION(extend);

zend_function_entry extend_functions[] = {
    ZEND_FE(myfirstfunc, NULL)
    ZEND_FE(myfirstfunc2, NULL)
    {NULL, NULL, NULL}
};

zend_module_entry extend_module_entry = {
    STANDARD_MODULE_HEADER,
        "My first PHP Extension",
        extend_functions,
        NULL, NULL, NULL, NULL,
        PHP_MINFO(extend),
        NO_VERSION_YET,
        STANDARD_MODULE_PROPERTIES
};

#if COMPILE_DL_EXTEND
    ZEND_GET_MODULE(extend)
#endif

PHP_MINFO_FUNCTION(extend) {
    php_info_print_table_start();
    php_info_print_table_header(2, "Extend the amazing php extension", "");
    php_info_print_table_row(2, "PHP Extension", "enabled");
    php_info_print_table_end();
}


ZEND_FUNCTION(myfirstfunc) {
    zend_printf("This is my first function");
}

ZEND_FUNCTION(myfirstfunc2) {
    zend_printf("This is my second function");
}



Output Window:
Code: Select all
Compiling...
php_extend.c
php_extend.c(1) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
c:\build\Zend\zend_execute.h(92) : warning C4311: 'type cast' : pointer truncation from 'void *' to 'ulong'
c:\build\Zend\zend_execute.h(104) : warning C4311: 'type cast' : pointer truncation from 'void *' to 'ulong'
php_extend.c(29) : warning C4013: 'php_info_print_table_start' undefined; assuming extern returning int
php_extend.c(30) : warning C4013: 'php_info_print_table_header' undefined; assuming extern returning int
php_extend.c(31) : warning C4013: 'php_info_print_table_row' undefined; assuming extern returning int
php_extend.c(32) : warning C4013: 'php_info_print_table_end' undefined; assuming extern returning int


Results:
Code: Select all
extend - 0 error(s), 7 warning(s)



I had to fix some errors in the tutorials code, there are some " & # 8 2 2 1 ; " (without spaces) things, I have replaced those with ", perhaps I misssed some other fixes.

Hope you can help, thanks in advance ;)
byte-aligned
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Aug 18, 2005 2:03 pm

Postby byte-aligned » Fri Aug 19, 2005 10:43 am

Still working on this, after some stupid mistakes Visual Studio compiles wothout complaints. Now I´m trying to do some basic ZendAPI functionality, I´m using this php script:
(C code below)

extend.php
Code: Select all
<?PHP
dl("php_extend.dll");

myfirstfunc();
myfirstfunc2();
?>


To load php_extend.dll, shouldnt this print the messages defined inside php_extend.c? I receive this errors:

Warning: dl(): Not supported in multithreaded Web servers - use extension statements in your php.ini in c:\apache\htdocs\extend.php on line 2

Fatal error: Call to undefined function: myfirstfunc() in c:\apache\htdocs\extend.php on line 4

Any ideas? :D



php_extend.h
Code: Select all
#define ZEND_WIN32
#define PHP_WIN32

#define ZEND_DEBUG 0
#define COMPILE_DL_EXTEND 1
#define ZTS 1
#include "php.h"


php_extend.c
Code: Select all
#include "php_extend.h"

ZEND_FUNCTION(myfirstfunc);
ZEND_FUNCTION(myfirstfunc2);

PHP_MINFO_FUNCTION(extend);

zend_function_entry extend_functions[] = {
    ZEND_FE(myfirstfunc, NULL)
    ZEND_FE(myfirstfunc2, NULL)
    {NULL, NULL, NULL}
};

zend_module_entry extend_module_entry = {
    STANDARD_MODULE_HEADER,
        "My first PHP Extension",
        extend_functions,
        NULL, NULL, NULL, NULL,
        PHP_MINFO(extend),
        NO_VERSION_YET,
        STANDARD_MODULE_PROPERTIES
};

#if COMPILE_DL_EXTEND
    ZEND_GET_MODULE(extend)
#endif

PHP_MINFO_FUNCTION(extend) {
    php_info_print_table_start();
    php_info_print_table_header(2, "Extend the amazing php extension", "");
    php_info_print_table_row(2, "PHP Extension", "enabled");
    php_info_print_table_end();
}


ZEND_FUNCTION(myfirstfunc) {
    zend_printf("This is my first function");
}

ZEND_FUNCTION(myfirstfunc2) {
    zend_printf("This is my second function");
}
byte-aligned
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Aug 18, 2005 2:03 pm

Postby byte-aligned » Fri Aug 19, 2005 11:45 am

Tried removing dl() and adding the extension with php.ini, same result, differente message :P

Fatal error: Call to undefined function: myfirstfunc() in c:\apache\htdocs\extend.php on line 3

:help:
byte-aligned
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Aug 18, 2005 2:03 pm

Postby Alexej Kubarev » Sat Aug 20, 2005 1:15 am

hmmz..im not really sure about building own extentions... but it definately doesnt find your extention or it doesnt work correctly..
will take a look at what we can do..
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby byte-aligned » Tue Aug 23, 2005 10:12 am

Still stuck at the same point :-x ... I think it can be something I´m missing on the VS .NET 2003 configuration.

This is my configuration (in Property Pages):
Addiotional Include Directories: E:\PHP;E:\PHP\main;E:\PHP\TSRM;E:\PHP\win32;E:\PHP\Zend

C/C++
Preprocessor: WIN32;NDEBUG;_WINDOWS;_USRDLL;COMPILADO_EXPORTS

Also in the .h file are some others. The warnings about php_info_print_table_start also look suspicious. Any idea why I receive those four warnings?
byte-aligned
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Aug 18, 2005 2:03 pm

Postby Alexej Kubarev » Wed Aug 24, 2005 8:28 am

didnt really find anything that might help... :(
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län


Return to PEAR and PECL

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.