Questions about compiling PHP extension components on Windows

Source: Internet
Author: User
Tags zts
How to compile PHP extension components on Windows? In the past two days, we need to compile a PHP extension to implement specific functions. after referring to the N-plus articles on the Internet, we found two pieces of baby, one is php_screw and the other is Cygwin. First, compile php_screw so that you can have a perceptual impression that it is okay to compile PHP extension components on Windows.

?

In the past two days, we need to compile a PHP extension to implement specific functions. after referring to the N-plus articles on the Internet, we found two pieces of baby, one is php_screw and the other is Cygwin.
First, compile php_screw so that you can have a perceptual impression that it is okay to pass the compilation, and then try to add some code to it. Finally, the compilation was successful. However, when I try it on Apache, memory read/write exceptions often occur. it has not been solved after the repair and modification for a long time.

As a result, I want to re-start it myself. refer to php_screw to add a little code to it to see if the problem can be solved.
According to the online tutorial, run the following command in Cygwin:
? Php ext_skel_win32.php -- extname = mytest
Generate the testing application framework and compile the framework directly. everything went smoothly. Then, add a function to it and put it in Apache for testing. However, the following two functions are available:
PHP_MINIT_FUNCTION (mytest)
And
PHP_MSHUTDOWN_FUNCTION (mytest)
Added before return SUCCESS
CG (extended_info) = 1;
And then compile, a compilation error occurs:

Deleting intermediate files and output files for project 'mytest - Win32 Debug_TS'.--------------------Configuration: mytest - Win32 Debug_TS--------------------Compiling...mytest.cLinking...   Creating library Debug_TS/php_mytest.lib and object Debug_TS/php_mytest.expmytest.obj : error LNK2001: unresolved external symbol _compiler_globals_id..\..\Debug_TS/php_mytest.dll : fatal error LNK1120: 1 unresolved externalsError executing link.exe.Creating browse info file...php_mytest.dll - 2 error(s), 0 warning(s)

?

After searching for the Internet for a long time, I did not try it, so I suspected it was a compiler configuration problem. so I opened the php_screw and mytest projects and compared the compilation parameters. Finally, I found:
The automatically generated compilation parameters are as follows: Project --> Setting --> C/C ++ --> Preprocessor definitions ::
ZEND_DEBUG = 1, WIN32, NDEBUG, _ WINDOWS, _ MBCS, _ USRDLL, MYTEST_EXPORTS, COMPILE_DL_MYTEST, ZTS = 1, ZEND_WIN32, PHP_WIN32, HAVE_MYTEST = 1,LIBZEND_EXPORTS
The php_screw parameter is as follows:
ZEND_DEBUG = 0, WIN32, NDEBUG, _ WINDOWS, _ MBCS, _ USRDLL, SCREW_EXPORTS, COMPILE_DL_SCREW, ZTS = 1, ZEND_WIN32, PHP_WIN32, HAVE_SCREW = 1
, We can see that:
1. automatically generate ZEND_DEBUG = 1 for the framework, and ZEND_DEBUG = 0 for php_screw;
2. automatically generate one more LIBZEND_EXPORTS parameter in the framework;
I tested the two parameters respectively:
1. change ZEND_DEBUG = 1 to ZEND_DEBUG = 0, and compile again. The error is as follows:

Deleting intermediate files and output files for project 'mytest - Win32 Debug_TS'.--------------------Configuration: mytest - Win32 Debug_TS--------------------Compiling...mytest.cLinking...   Creating library Debug_TS/php_mytest.lib and object Debug_TS/php_mytest.expmytest.obj : error LNK2001: unresolved external symbol _compiler_globals_id..\..\Debug_TS/php_mytest.dll : fatal error LNK1120: 1 unresolved externalsError executing link.exe.Creating browse info file...php_mytest.dll - 2 error(s), 0 warning(s)

?

2. remove LIBZEND_EXPORTS and compile the LIBZEND_EXPORTS. the error disappears:

Deleting intermediate files and output files for project 'mytest - Win32 Debug_TS'.--------------------Configuration: mytest - Win32 Debug_TS--------------------Compiling...mytest.cLinking...   Creating library Debug_TS/php_mytest.lib and object Debug_TS/php_mytest.expCreating browse info file...php_mytest.dll - 0 error(s), 0 warning(s)

?

3. change ZEND_DEBUG = 0 to ZEND_DEBUG = 1 and compile again. no error occurs:

Deleting intermediate files and output files for project 'mytest - Win32 Debug_TS'.--------------------Configuration: mytest - Win32 Debug_TS--------------------Compiling...mytest.cLinking...   Creating library Debug_TS/php_mytest.lib and object Debug_TS/php_mytest.expCreating browse info file...php_mytest.dll - 0 error(s), 0 warning(s)

?

Therefore, the problem is caused by the LIBZEND_EXPORTS parameter. However, due to the fact that you are not familiar with VC and are more familiar with Zend APIs, you can only know the Zend APIs, but you cannot understand them either;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.