Compiling a PHP extension as non-thread safe

I am trying to compile the imagemagick (imagick) extension for use in a non-threading environment on windows.

I am using PHP 5.3.10 and have configured Visual C ++ express as my compilation environment. The problem is that I'm using a non-threaded version of PHP as the FCGI module in Apache 2.2.

This way my PHP comes with php5.lib , not php5ts.lib . I believe that it is for this reason that I get these errors:

 imagick.obj : error LNK2019: unresolved external symbol __imp__tsrm_mutex_alloc referenced in function _zm_startup_imagick 

I only ever created and compiled things on Linux, so I'm not too sure how to do this on a Windows environment.

How can I compile the extension so that it is not thread safe?


I downloaded the PHP 5.3.10 file binary to get a copy of php5ts.lib. Then I was able to compile the extension.

I assume that setting the ZTS preprocessor directive to 1 or 0 will cause the extension to compile both thread-safe and non-stream. (Not too sure about this, so if someone can tell me if this is correct or not, that would be very appreciated. :))

Then I set up a virtual machine running Windows 7 and installed the latest version of WAMP. The reason is that he used a streaming version of PHP.

I placed the dll in the ext folder in the PHP installation and included it in php.ini . However, even after trying to use the ts and nts version in WAMP, I would get:

 PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.3.10/ext/imagick.dll' - The specified module could not be found. in Unknown on line 0 

But the fact is that c:/wamp/bin/php/php5.3.10/ext/imagick.dll' exists, and yes, I checked it many times.

Then I downgraded ImageMagick to 6.6.2-10-Q16, but still see the same problem.

The same problem occurs on my dev machine, which runs the nts version of PHP 5.3.10 on Apache 2.2 (everything is installed manually).


Looks like I was wrong about the ZTS preprocessor. If I set ZTS=0 and compile, using the dependent walker on the compiled dll still shows that it requires php5ts.dll , which is only present in thread safe versions of PHP.


I was more interested in finding dependencies and found that I had to statistically refer to msvc100d.dll. Then I removed ZTS in the preprocessor definition and was able to compile using php5.lib instead of php5ts.dll . I think this should get me non-ts dll.

However, when I download the extension, I still get:

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

And errors from walking dependencies:

 Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module. Error: Modules with different CPU types were found. Warning: At least one delay-load dependency module was not found. Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module. 

Installed visual C ++ express 2008 and compiled using the v90 platform toolkit, but still faces the same problems.

Any advice appreciated :)


Solution found! See my answer.

+6
source share
2 answers

Got! Hope this helps in compiling php extensions on Windows in the future. What I did is based on: https://wiki.php.net/internals/windows/stepbystepbuild

Note. I read the answer on this site that says compiling PHP extensions on windows itself is not supported. Based on my experiments yesterday, this seems to be a lot of work, so I use the PHP build process.

The best way is to use the PHP build process.

  • Install Visual C ++ Express 2008 (any version will work, but the express is free) and Windows SDK 6.1 (note that we want version 6.1 not to be something older or newer).

  • Install the SVN client tools if you havenโ€™t done so, and restart the PATH variable to take effect.

  • Get the binary tools of the PHP SDK and extract it to C:\php-sdk .

  • Launch the CMD Shell in the Microsoft Windows SDK v6.1 of your start menu and run cd C:\php-sdk .

  • Running setenv /x86 /xp /release creates a 32-bit version. You can use /x64 to create a 64-bit version (I have not tried this).

  • run bin\phpsdk_setvars.bat

  • run bin\phpsdk_buildtree.bat php53dev

  • Download the PHP source code and extract it to C:\php-sdk\php53dev\vc9\x86 so that you get C:\php-sdk\php53dev\vc9\x86\php5.3-xyz

  • Download the latest deps and extract everything up to C:\php-sdk\php53dev\vc9\x86 . You may be prompted to overwrite all existing folders, so click Yes.

  • run cd C:\php-sdk\php53dev\vc9\x86

  • Check out the latest version of your extension from the svn repository: svn co http://svn.php.net/repository/pecl/imagick/trunk pecl/imagick Here I am viewing the image.

  • Install any dependencies. In my case, I need to install ImageMagick, so I downloaded the latest recommended Windows binary . You will need to restart after installation to update the PATH variable, but you can do it after you compiled. Make sure you set the C / C ++ headers and enable it as well.

  • Copy the contents of the includes directory from the ImageMagick installation directory to C:\php-sdk\php53dev\vc9\x86\deps\include .

  • Copy the contents of the lib directory from the ImageMagick installation directory to C:\php-sdk\php53dev\vc9\x86\deps\lib

  • Now let's build: run cd C:\php-sdk\php53dev\vc9\x86\php5.3-xyz , then buildconf , then configure --help . Look for help properly. It will show you all the configuration flags and any available extensions to enable. In my case, since I added imagick, I had an option called --with-imagick

  • Run the configuration: configure --enable-cli --with-imagick=shared --disable-zts If you want to create an unsafe binary using --disable-zts , otherwise remove this configuration flag. I'm not sure why, but sometimes extensions use the --with-myextension , and sometimes --enable-myextension , so check configure --help for the flag used. If you add =shared after the extension flag, it will be compiled as a separate DLL, which we need.

  • Compile: run nmake , then nmake snap .

  • Done :) Check C:\php-sdk\php53dev\vc9\x86\php-5.3.10\Release (not thread safe) or C:\php-sdk\php53dev\vc9\x86\php-5.3.10\Release_TS ( thread safe). Your compiled binaries should be there. Compiled extensions (pecl) must be in a ZIP file similar to pecl-5.3.10-nts-Win32-VC9-x86.zip . Open this file and extract the extensio library to the ext folder in your PHP installation.

  • Enable the PHP extension and restart the web server. Run phpinfo() and make sure the extension is enabled.

  • If the extension does not work properly, make sure you restart the update of your PATH variable. In my case, I need to set the imagemagick installation directory in my PATH variable.

  • ???

  • Profit!

+5
source

Is there a reason you need to compile? Why not download? This is usually much simpler / faster on Windows.

VC6: http://www.sk89q.com/2010/03/vc6-windows-binaries-for-imagick-2-3-0/

VC9: http://valokuva.org/builds/

0
source

Source: https://habr.com/ru/post/912820/


All Articles