Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling PHP on Windows with /MT

Tags:

c++

php

I need to link PHP statically to a project on which I am working. In order to do this, I believe that I need to compile PHP with /MT, but it appears that it is being done in /MD.

The only real documentation I have been able to find on compiling PHP is at https://wiki.php.net/internals/windows/stepbystepbuild and this does not cover my requirement.

Can this be done, or am I incorrect in my assumptions?

like image 859
Jack Murdoch Avatar asked May 06 '26 10:05

Jack Murdoch


1 Answers

Not sure why exactly you want to do this, but you can come pretty close by building PHP as a static binary and using that binary later from your C++ application. This should be portable and should meet your requirements without actually linking it to your application.

To do this, you need to include --enable-static when configuring. For example:

./configure --enable-static=yes \
    --enable-fastcgi \
    --enable-force-cgi-redirect \
    --enable-discard-path \
    --prefix=/server/php \
    --exec-prefix=/server/php \
    --with-config-file-path=/server/php \
    --disable-all \
    --enable-shared=no \
    --enable-session \
    --with-gd \
    --with-zlib-dir \
    --with-freetype-dir \
    --enable-sockets
    --with-freetype-dir=/usr/local

You should also add the -all-static flag to the BUILD_CGI in your Makefile. After that run make and you should get a static PHP binary. You can now use it from your C++ project without any external requirements for it.

On the other hand, if you can meet your requirements by creating a C++ PHP extension, you should take a look at PHP-CPP:

The PHP-CPP library is a C++ library for developing PHP extensions. It offers a collection of well documented and easy-to-use classes that can be used and extended to build native extensions for PHP.

like image 138
bosnjak Avatar answered May 08 '26 00:05

bosnjak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!