How do I compile a PHP extension with Microsoft Visual C++ 2008?
Asked Answered
S

3

8

I created a PHP Hello World extension DLL with Microsoft Visual C++ 2008. I have the right php.ini (I know because when I enable and disable the gd2 extension, there is an effect), but when I load the extension it does not pop up under the Additional Modules in phpinfo().

When I try to test the function (a simple double() function) it obviously does not work. I used this tutorial).

If someone could supply their dll created when doing this (to see If mine's messed up or if it's my server) then I'd gladly test it.

System Specs

OS: Windows (Vista)
Server: WAMP
PHP: 5.3.5 (Xampp and IIS also installed)

When I run the command php --ini i get this error:

PHP Startup: TalkPHP Extension: Unable to initalize module
Module compiled with build ID=API20090626, TS, VC9.
PHP   compiled with build IF=API20090626, TS, VC6.
These options need to match

Does this mean I have to use Version 9 to compile PHP?

Sniffle answered 5/2, 2011 at 15:34 Comment(18)
What is your OS and your webserver ?Gnomic
Did you restart? Did you try loading it via dl("yourext.dll"); instead?Thereunder
for some reason when I enable dl() it says it''s enabled in phpinfo() but says it's an undefined function on my programSniffle
I added the DLL so it can be tested by othersSniffle
Run the command php --ini to be sure of the php.ini loaded :)Barrack
When I run the command php --ini i get this error PHP Startup: TalkPHP Extension: Unable to initalize module. Module compiled with build ID=API20090626, TS, VC9. PHP compiled with build IF=API20090626, TS, VC6. These options need to matchSniffle
dl() might been added to disabled_functions directive.Prop
@ludesign: dl() is deprecated in PHP v5.3.0+ I believe and is removed in a number of SAPIs.Wilkison
That explains it (it was not in the disable_functions anyways) and i believe now that the problem has too do with the reload of the .ini. See the error aboveSniffle
Thanks for mentioning that @Orbling. :)Prop
I found the solution forums.zend.com/viewtopic.php?f=55&t=2045 and this might be marked as possible duplication of this question: forums.zend.com/viewtopic.php?f=55&t=2045Prop
@ludesign: Second link not the right one there? ;-)Wilkison
@Wilkison I am sorry, it's quite a late here (3:30AM). This is the correct link to the question: #3642251Prop
I get this error c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(437) : see previous definition of 'putwchar' c:\wamp\bin\php\php-5.3.5src\zend\zend_build.h(19) : warning C4005: 'PHP_COMPILER_ID' : macro redefinition c:\wamp\bin\php\php-5.3.5src\main\config.w32.h(189) : see previous definition of 'PHP_COMPILER_ID' 1>c:\wamp\bin\php\php-5.3.5src\main\config.w32.h(189) : warning C4005: 'PHP_COMPILER_ID' : macro redefinition 1> c:\wamp\bin\php\php-5.3.5src\zend\zend_build.h(19) : see previous definition of 'PHP_COMPILER_ID'Sniffle
I think it has to do with the fact that mine actually says compiled with VC9 and on the others it has nothing. (They're warnings but I think it's why it doesn't work)Sniffle
I will install VS2008 and try the same tutorial, I have build few extensions in the past but only once I had to compile them for windows and for this I used VS6 (apache restrictions). Will post back in about 20 minutes. Hope I will manage to get this working.Prop
@lidesign Ok, did nothing more but just tried it but when I ran the extension it WORKED. I still got errors from php --ini but it ran and WORKED. Thank you so much. Hope you try it and like it anyways.Sniffle
@Mark you should move the comment that is the answer into an answer and in two days, mark it as the answer. That's how things are marked as 'solved'.Monophonic
S
1

Solution from the comments...

-I found the solution forums.zend.com/viewtopic.php?f=55&t=2045

-Possible duplicate: question: stackoverflow.com/questions/3641751/

I get these warnings

c:\wamp\bin\php\php-5.3.5src\zend\zend_build.h(19) : warning C4005: 'PHP_COMPILER_ID': macro redefinition c:\wamp\bin\php\php-5.3.5src\main\config.w32.h(189) : see previous definition of 'PHP_COMPILER_ID' 1>
c:\wamp\bin\php\php-5.3.5src\main\config.w32.h(189) : warning C4005: 'PHP_COMPILER_ID' : macro redefinition 1> 
c:\wamp\bin\php\php-5.3.5src\zend\zend_build.h(19) : see previous definition of'PHP_COMPILER_ID'

I think it has to do with the fact that mine actually says compiled with VC9 and on the others it has nothing. (They're warnings but I think it's why it doesn't work)

Ok, did nothing more but just tried it but when I ran the extension it WORKED. I still got errors from php --ini but it ran and WORKED.

Sniffle answered 8/2, 2011 at 0:5 Comment(0)
S
2

VC9 and VC6 builds are not compatible. You either have to compile your DLL with VC6 or get PHP binaries compiled with VC9 from their download page.

If you are using Apache and mod_php you will also need a VC9 build of Apache to load the VC9 PHP, you can get those from apachehaus.com.

Sheepshearing answered 7/2, 2011 at 15:39 Comment(0)
S
1

Solution from the comments...

-I found the solution forums.zend.com/viewtopic.php?f=55&t=2045

-Possible duplicate: question: stackoverflow.com/questions/3641751/

I get these warnings

c:\wamp\bin\php\php-5.3.5src\zend\zend_build.h(19) : warning C4005: 'PHP_COMPILER_ID': macro redefinition c:\wamp\bin\php\php-5.3.5src\main\config.w32.h(189) : see previous definition of 'PHP_COMPILER_ID' 1>
c:\wamp\bin\php\php-5.3.5src\main\config.w32.h(189) : warning C4005: 'PHP_COMPILER_ID' : macro redefinition 1> 
c:\wamp\bin\php\php-5.3.5src\zend\zend_build.h(19) : see previous definition of'PHP_COMPILER_ID'

I think it has to do with the fact that mine actually says compiled with VC9 and on the others it has nothing. (They're warnings but I think it's why it doesn't work)

Ok, did nothing more but just tried it but when I ran the extension it WORKED. I still got errors from php --ini but it ran and WORKED.

Sniffle answered 8/2, 2011 at 0:5 Comment(0)
S
0

I compiled and run successfully a custom php extension.

Can you try the following:

  • get the vc9 build from php-5.3.5
  • don't #define PHP_COMPILER_ID in the zend_build.h header file (IMHO that's a bad idea anyway)
  • you probably defined PHP_COMPILER_ID in config.w32.h, too; remove it
  • in your project settings (C/C++ - Preprocessor) define: PHP_COMPILER_ID=\"VC9\" (if you need the vc6 build of php then I would try to define PHP_COMPILER_ID=\"VC6\"; I don't know whether this works without problems but I've used the constellation [php-5.2.x vc6, custom php extension compiled with vc9] without problems, ever)
Sloven answered 15/2, 2011 at 22:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.