Compile PHP-CPP on Windows Machine

562 views Asked by At

I`m trying develop a extension to PHP with PHP-CPP on Windows. I build the .a and .so of PHP-CPP with MingW, but, when i go build the extension the compiler not found the phpcpp.h.
My file Makefile:

NAME                    =   Teste
INI_DIR             =   /etc/php5/conf.d
EXTENSION_DIR           =   $(shell php-config --extension-dir)
EXTENSION           =   ${NAME}.so
INI                     =   ${NAME}.ini
COMPILER                =   g++
LINKER              =   g++
COMPILER_FLAGS      =   -Wall -c -O2 -std=c++11 -fpic -o
LINKER_FLAGS            =   -shared
LINKER_DEPENDENCIES =   -lphpcpp
RM                  =   rm -f
CP                  =   cp -f
MKDIR                   =   mkdir -p
SOURCES             =   $(wildcard *.cpp)
OBJECTS             =   $(SOURCES:%.cpp=%.o)
all:                    ${OBJECTS} ${EXTENSION}
${EXTENSION}:           ${OBJECTS}
                ${LINKER} ${LINKER_FLAGS} -o $@ ${OBJECTS}         
${LINKER_DEPENDENCIES}
${OBJECTS}:
                ${COMPILER} ${COMPILER_FLAGS} $@ ${@:%.o=%.cpp}
install:        
                ${CP} ${EXTENSION} ${EXTENSION_DIR}
                ${CP} ${INI} ${INI_DIR}
clean:
                ${RM} ${EXTENSION} ${OBJECTS}


Folder Structure:
main.cpp
Makefile
phpcpp.a
phpcpp.so

Sorry for my bad English.

2

There are 2 answers

0
Ensai Tankado On

You can try to generate a visual studio project with cmake / cmake gui - there is a "CMakeLists.txt" in the root folder of "PHP-CPP" Directory.

Now you can compile it with msvc ... but be aware of the mixed code from c and c++ - there are some .c headers included - maybe you have to edit some compiler options ...

0
Ensai Tankado On

You can try the following to generate an .dll of phpcpp with Linux (here Ubuntu):

First be sure you have installed the PHP version 7.4. The "dev" as also the "standard" package of PHP 7.4.

Now compile the PHPCPP with "sudo make" in the main Folder of PHPCPP.

Now you got some ".o" files. These are located in the /shared/zend/ of the main PHPCPP Folder.

Now you can create an ".dll" File out of these ".o" files - like the following (extracted from here):

sudo g++ -shared -o phpcpp.dll zval.o zendcallable.o valueiterator.o value.o throwable.o super.o streams.o streambuf.o stream.o script.o sapi.o object.o namespace.o module.o members.o base.o callable.o eval.o classbase.o classimpl.o constant.o constantfuncs.o error.o exception.o exception_handler.o exists.o extension.o extensionimpl.o file.o function.o functor.o global.o globals.o hashmember.o ini.o inivalue.o iteratorimpl.o

it is not completely tested ... be careful ...