Search code examples
phpwindowsphp-extension

compiling shared php-module as dll (windows)


i'm trying to compile a shared extension for php 8.3.6 x64 for windows i basicly followed these instructions: https://ourcodeworld.com/articles/read/804/how-to-compile-a-php-extension-dll-file-in-windows-with-visual-studio#disqus_thread

Problem: PHP Warning: PHP Startup: Unable to load dynamic library 'php_mailparse.dll' (tried: ./ext\php_mailparse.dll (Die angegebene Prozedur wurde nicht gefunden)) in Unknown on line 0

so what did i do:

  • installed basic components of Visual Studio 2019
  • create folder c:\php-sdk
  • extracted php-source from https://www.php.net/distributions/php-8.3.6.tar.gz into php-sdk
  • extracted contents of https://pecl.php.net/get/mailparse-3.1.6.tgz to php-sdk/ext/mailparse as of instructions i should run buildconf and configure, what it said binary tools are missing, so
  • downloaded https://github.com/php/php-sdk-binary-tools and extracted to php-sdk/php-sdk-binary-tools-master
  • open vs command prompt
  • goto php-sdk/php-sdk-binary-tools-master
  • run phpsdk-vs16-x64.bat
  • go back to php-sdk
  • run configure --disable-all --enable-cli --enable-mbstring --enable-mailparse --disable-zts --with-all-shared output:
-----------------------
| Extension  | Mode   |
-----------------------
...
| mailparse  | shared |
...
-----------------------


Enabled SAPI:
-------------
| Sapi Name |
-------------
| cli       |
-------------

-----------------------------------------
| Build type          | Release         |
| Thread Safety       | No              |
| Compiler            | Visual C++ 2019 |
| Target Architecture | x64             |
| Host Architecture   | x64             |
| Optimization        | PGO disabled    |
| Native intrinsics   | SSE2            |
| Static analyzer     | disabled        |
-----------------------------------------
  • run nmake

now in php-sdk\x64\Release i found a php_mailparse.dll, [edit] and copied it to the ext-folder of the precompiled php-binaries, [/edit] but this dll gives me the error written at the beginning ... anybody know what i've done wrong?


Solution

  • thanks to @shingo and a little experiment i got it working, as @shingo posted in his comment compiling shared php-module as dll (windows) i've done the following based on the instructions of https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2#building_pecl_extensions

    i have installed Visual Studio Community 2019 with the following components (i don't know which one a really needed, just glad it worked overall ^^)

    • Desktopdevelopment with C++
    • MSVC v142 - VS 2019 C++ -x64/x86Buildtools
    • Windows 10 SDK
    • Just-In-Time-Debugger
    • C++-Profilingtools
    • C++-CMake-Tools for Windows
    • C++ AddressSanitizer

    now:

    • create folder C:\php-sdk

    • extract php-source to C:\php-sdk (now i had the php source in C:\php-sdk\php-8.3.6-src)

    • extract contents php-sdk-binary-tools-master.zip\php-sdk-binary-tools-master to C:\php-sdk (so that for exmaple phpsdk-vs16-x64.bat will be in C:\php-sdk)

    • go into php-src-folder (C:\php-sdk\php-8.3.6-src in my case) and create a folder "pecl"

    • extract src of extension to C:\php-sdk\php-8.3.6-src\pecl (in my case mailparse, so i had a folder C:\php-sdk\php-8.3.6-src\pecl\pecl-mail-mailparse-master, but i renamed it to C:\php-sdk\php-8.3.6-src\pecl\mailparse)

    now open command prompt:

    • cd C:\php-sdk
    • phpsdk-vs16-x64.bat
    • cd php-8.3.6-src
    • buildconf
    • configure --disable-all --enable-cli --enable-mbstring=shared --enable-mailparse=shared --disable-zts (--disable-zts because i'm compiling for fastcgi under iis, also --enable-mbstring=shared was necessary, since mailparse depends on mbstring, without it, it did not work)
    • nmake

    now i copied php_mbstring.dll and php_mailparse.dll from C:\php-sdk\php-8.3.6-src\x64\Release to the extension-folder of my running prebuild php-binaries ext-folder, REPLACING the existing php_mbstring.dll and now it works ;)