php-opencv / php-opencv

opencv 4.5+ with dnn module for php 7/8

Home Page:https://github.com/php-opencv/php-opencv-examples

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support php 7.3/7.4/8.0

morozovsk opened this issue · comments

php 7.3 has broken internal api for extensions.
So php-opencv will not work on php 7.3+.
May be someone can fix it.
I tried but unsuccessful.
If you can do it please send pull request.

php 7.4 supports ffi but ffi works only with C not C++ (opencv is writen on C++).

PS: you can still docker
https://github.com/php-opencv/php-opencv-examples/wiki/installation-via-docker
https://github.com/php-opencv/php-opencv-examples/tree/master/docker

@morozovsk could you please show to us what you try ?

I try with opencv 4.1.1 and php-fpm 7.3, and it's seems to work :
Capture d’écran du 2020-12-17 10-10-25

I can't check on php 7.3 but on php 7.4 (ubuntu 20.10):

>cd php-opencv && phpize && ./configure --with-php-config=/usr/bin/php-config && make

Configuring for:
PHP Api Version:         20190902
Zend Module Api No:      20190902
Zend Extension Api No:   320190902
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20190902
checking for PHP installed headers prefix... /usr/include/php/20190902
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for opencv support... yes, shared
checking for php debug... no
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for pkg-config... found
checking for opencv... found 4.0.1
checking for a sed that does not truncate output... /usr/bin/sed
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking how to run the C++ preprocessor... g++ -E
checking the maximum length of command line arguments... 1572864
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
checking for ld used by g++... /usr/bin/ld -m elf_x86_64
checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC
checking if g++ PIC flag -fPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... GNU/Linux ld.so
(cached) (cached) checking how to hardcode library paths into programs... immediate
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
/bin/bash /php-opencv/libtool --mode=compile g++ -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/php-opencv -DPHP_ATOM_INC -I/php-opencv/include -I/php-opencv/main -I/php-opencv -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/usr/local/include/opencv4/opencv -I/usr/local/include/opencv4  -DHAVE_CONFIG_H  -g -O2   -c /php-opencv/opencv.cc -o opencv.lo 
mkdir .libs
 g++ -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/php-opencv -DPHP_ATOM_INC -I/php-opencv/include -I/php-opencv/main -I/php-opencv -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/usr/local/include/opencv4/opencv -I/usr/local/include/opencv4 -DHAVE_CONFIG_H -g -O2 -c /php-opencv/opencv.cc  -fPIC -DPIC -o .libs/opencv.o
/bin/bash /php-opencv/libtool --mode=compile g++ -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/php-opencv -DPHP_ATOM_INC -I/php-opencv/include -I/php-opencv/main -I/php-opencv -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/usr/local/include/opencv4/opencv -I/usr/local/include/opencv4  -DHAVE_CONFIG_H  -g -O2   -c /php-opencv/source/opencv2/core/opencv_mat.cc -o source/opencv2/core/opencv_mat.lo 
mkdir source/opencv2/core/.libs
 g++ -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -I. -I/php-opencv -DPHP_ATOM_INC -I/php-opencv/include -I/php-opencv/main -I/php-opencv -I/usr/include/php/20190902 -I/usr/include/php/20190902/main -I/usr/include/php/20190902/TSRM -I/usr/include/php/20190902/Zend -I/usr/include/php/20190902/ext -I/usr/include/php/20190902/ext/date/lib -I/usr/local/include/opencv4/opencv -I/usr/local/include/opencv4 -DHAVE_CONFIG_H -g -O2 -c /php-opencv/source/opencv2/core/opencv_mat.cc  -fPIC -DPIC -o source/opencv2/core/.libs/opencv_mat.o
/php-opencv/source/opencv2/core/opencv_mat.cc: In function 'void opencv_mat_init()':
/php-opencv/source/opencv2/core/opencv_mat.cc:858:49: error: invalid conversion from 'void (*)(zval*, zval*, zval*, void**)' {aka 'void (*)(_zval_struct*, _zval_struct*, _zval_struct*, void**)'} to 'zend_object_write_property_t' {aka '_zval_struct* (*)(_zval_struct*, _zval_struct*, _zval_struct*, void**)'} [-fpermissive]
  858 |     opencv_mat_object_handlers.write_property = opencv_mat_write_property;
      |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                 |
      |                                                 void (*)(zval*, zval*, zval*, void**) {aka void (*)(_zval_struct*, _zval_struct*, _zval_struct*, void**)}
make: *** [Makefile:194: source/opencv2/core/opencv_mat.lo] Error 1

@morozovsk , ok, that's strange, on my side, with alpine image base, php-opencv is compiled, but the so library is missing some link to over parts.

See here => benjy8001/php-fpm-opencv#1

php 8.0 ubuntu 20.10:

Step 9/11 : RUN cd php-opencv && phpize && ./configure --with-php-config=/usr/bin/php-config && make
 ---> Running in 47e71c244ee9
Configuring for:
PHP Api Version:         20200930
Zend Module Api No:      20200930
Zend Extension Api No:   420200930
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php/20200930 -I/usr/include/php/20200930/main -I/usr/include/php/20200930/TSRM -I/usr/include/php/20200930/Zend -I/usr/include/php/20200930/ext -I/usr/include/php/20200930/ext/date/lib
checking for PHP extension directory... /usr/lib/php/20200930
checking for PHP installed headers prefix... /usr/include/php/20200930
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking for opencv support... yes, shared
checking for php debug... no
checking for g++... g++
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking for pkg-config... found
checking for opencv... found 4.5.0
checking how to print strings... printf
checking for a sed that does not truncate output... (cached) /usr/bin/sed
checking for fgrep... /usr/bin/grep -F
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... @
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... (cached) nawk
checking command to parse /usr/bin/nm -B output from cc object... ok
checking for sysroot... no
checking for a working dd... /usr/bin/dd
checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if cc supports -fno-rtti -fno-exceptions... no
checking for cc option to produce PIC... -fPIC -DPIC
checking if cc PIC flag -fPIC -DPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking if cc supports -c -o file.o... (cached) yes
checking whether the cc linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
checking how to run the C++ preprocessor... g++ -E
checking for ld used by g++... /usr/bin/ld -m elf_x86_64
checking if the linker (/usr/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking for g++ option to produce PIC... -fPIC -DPIC
checking if g++ PIC flag -fPIC -DPIC works... yes
checking if g++ static flag -static works... yes
checking if g++ supports -c -o file.o... yes
checking if g++ supports -c -o file.o... (cached) yes
checking whether the g++ linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking dynamic linker characteristics... (cached) GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h
config.status: executing libtool commands
/bin/bash /php-opencv/libtool --mode=compile g++ -I. -I/php-opencv -I/php-opencv/include -I/php-opencv/main -I/php-opencv -I/usr/include/php/20200930 -I/usr/include/php/20200930/main -I/usr/include/php/20200930/TSRM -I/usr/include/php/20200930/Zend -I/usr/include/php/20200930/ext -I/usr/include/php/20200930/ext/date/lib -I/usr/local/include/opencv4  -DHAVE_CONFIG_H  -g -O2   -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /php-opencv/opencv.cc -o opencv.lo 
libtool: compile:  g++ -I. -I/php-opencv -I/php-opencv/include -I/php-opencv/main -I/php-opencv -I/usr/include/php/20200930 -I/usr/include/php/20200930/main -I/usr/include/php/20200930/TSRM -I/usr/include/php/20200930/Zend -I/usr/include/php/20200930/ext -I/usr/include/php/20200930/ext/date/lib -I/usr/local/include/opencv4 -DHAVE_CONFIG_H -g -O2 -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /php-opencv/opencv.cc  -fPIC -DPIC -o .libs/opencv.o
/bin/bash /php-opencv/libtool --mode=compile g++ -I. -I/php-opencv -I/php-opencv/include -I/php-opencv/main -I/php-opencv -I/usr/include/php/20200930 -I/usr/include/php/20200930/main -I/usr/include/php/20200930/TSRM -I/usr/include/php/20200930/Zend -I/usr/include/php/20200930/ext -I/usr/include/php/20200930/ext/date/lib -I/usr/local/include/opencv4  -DHAVE_CONFIG_H  -g -O2   -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /php-opencv/source/opencv2/core/opencv_mat.cc -o source/opencv2/core/opencv_mat.lo 
libtool: compile:  g++ -I. -I/php-opencv -I/php-opencv/include -I/php-opencv/main -I/php-opencv -I/usr/include/php/20200930 -I/usr/include/php/20200930/main -I/usr/include/php/20200930/TSRM -I/usr/include/php/20200930/Zend -I/usr/include/php/20200930/ext -I/usr/include/php/20200930/ext/date/lib -I/usr/local/include/opencv4 -DHAVE_CONFIG_H -g -O2 -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -c /php-opencv/source/opencv2/core/opencv_mat.cc  -fPIC -DPIC -o source/opencv2/core/.libs/opencv_mat.o
/php-opencv/source/opencv2/core/opencv_mat.cc: In function 'void opencv_mat_update_property_by_c_mat(zval*, cv::Mat*)':
/php-opencv/source/opencv2/core/opencv_mat.cc:53:46: error: cannot convert 'zval*' {aka '_zval_struct*'} to 'zend_object*' {aka '_zend_object*'}
   53 |     zend_update_property_long(opencv_mat_ce, z, "rows", sizeof("rows")-1, mat->rows);
      |                                              ^
      |                                              |
      |                                              zval* {aka _zval_struct*}
In file included from /usr/include/php/20200930/main/php.h:36,
                 from /php-opencv/source/opencv2/core/../../../php_opencv.h:23,
                 from /php-opencv/source/opencv2/core/opencv_mat.cc:18:
/usr/include/php/20200930/Zend/zend_API.h:390:79: note:   initializing argument 2 of 'void zend_update_property_long(zend_class_entry*, zend_object*, const char*, size_t, zend_long)'
  390 | ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
      |                                                                  ~~~~~~~~~~~~~^~~~~~
/php-opencv/source/opencv2/core/opencv_mat.cc:54:46: error: cannot convert 'zval*' {aka '_zval_struct*'} to 'zend_object*' {aka '_zend_object*'}
   54 |     zend_update_property_long(opencv_mat_ce, z, "cols", sizeof("cols")-1, mat->cols);
      |                                              ^
      |                                              |
      |                                              zval* {aka _zval_struct*}
In file included from /usr/include/php/20200930/main/php.h:36,
                 from /php-opencv/source/opencv2/core/../../../php_opencv.h:23,
                 from /php-opencv/source/opencv2/core/opencv_mat.cc:18:
/usr/include/php/20200930/Zend/zend_API.h:390:79: note:   initializing argument 2 of 'void zend_update_property_long(zend_class_entry*, zend_object*, const char*, size_t, zend_long)'
  390 | ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
      |                                                                  ~~~~~~~~~~~~~^~~~~~
/php-opencv/source/opencv2/core/opencv_mat.cc:55:46: error: cannot convert 'zval*' {aka '_zval_struct*'} to 'zend_object*' {aka '_zend_object*'}
   55 |     zend_update_property_long(opencv_mat_ce, z, "dims", sizeof("dims")-1, mat->dims);
      |                                              ^
      |                                              |
      |                                              zval* {aka _zval_struct*}
In file included from /usr/include/php/20200930/main/php.h:36,
                 from /php-opencv/source/opencv2/core/../../../php_opencv.h:23,
                 from /php-opencv/source/opencv2/core/opencv_mat.cc:18:
/usr/include/php/20200930/Zend/zend_API.h:390:79: note:   initializing argument 2 of 'void zend_update_property_long(zend_class_entry*, zend_object*, const char*, size_t, zend_long)'
  390 | ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
      |                                                                  ~~~~~~~~~~~~~^~~~~~
/php-opencv/source/opencv2/core/opencv_mat.cc:56:46: error: cannot convert 'zval*' {aka '_zval_struct*'} to 'zend_object*' {aka '_zend_object*'}
   56 |     zend_update_property_long(opencv_mat_ce, z, "type", sizeof("type")-1, mat->type());
      |                                              ^
      |                                              |
      |                                              zval* {aka _zval_struct*}
In file included from /usr/include/php/20200930/main/php.h:36,
                 from /php-opencv/source/opencv2/core/../../../php_opencv.h:23,
                 from /php-opencv/source/opencv2/core/opencv_mat.cc:18:
/usr/include/php/20200930/Zend/zend_API.h:390:79: note:   initializing argument 2 of 'void zend_update_property_long(zend_class_entry*, zend_object*, const char*, size_t, zend_long)'
  390 | ZEND_API void zend_update_property_long(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zend_long value);
      |                                                                  ~~~~~~~~~~~~~^~~~~~
/php-opencv/source/opencv2/core/opencv_mat.cc:66:45: error: cannot convert 'zval*' {aka '_zval_struct*'} to 'zend_object*' {aka '_zend_object*'}
   66 |         zend_update_property(opencv_mat_ce, z, "shape", sizeof("shape")-1, &shape_zval);
      |                                             ^
      |                                             |
      |                                             zval* {aka _zval_struct*}
In file included from /usr/include/php/20200930/main/php.h:36,
                 from /php-opencv/source/opencv2/core/../../../php_opencv.h:23,
                 from /php-opencv/source/opencv2/core/opencv_mat.cc:18:
/usr/include/php/20200930/Zend/zend_API.h:387:74: note:   initializing argument 2 of 'void zend_update_property(zend_class_entry*, zend_object*, const char*, size_t, zval*)'
  387 | ZEND_API void zend_update_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zval *value);
      |                                                             ~~~~~~~~~~~~~^~~~~~
/php-opencv/source/opencv2/core/opencv_mat.cc: In function 'void opencv_mat_write_property(zval*, zval*, zval*, void**)':
/php-opencv/source/opencv2/core/opencv_mat.cc:842:40: error: cannot convert 'zval*' {aka '_zval_struct*'} to 'zend_object*' {aka '_zend_object*'} in argument passing
  842 |     std_object_handlers.write_property(object,member,value,cache_slot);
      |                                        ^~~~~~
      |                                        |
      |                                        zval* {aka _zval_struct*}
/php-opencv/source/opencv2/core/opencv_mat.cc: In function 'void opencv_mat_init()':
/php-opencv/source/opencv2/core/opencv_mat.cc:858:49: error: invalid conversion from 'void (*)(zval*, zval*, zval*, void**)' {aka 'void (*)(_zval_struct*, _zval_struct*, _zval_struct*, void**)'} to 'zend_object_write_property_t' {aka '_zval_struct* (*)(_zend_object*, _zend_string*, _zval_struct*, void**)'} [-fpermissive]
  858 |     opencv_mat_object_handlers.write_property = opencv_mat_write_property;
      |                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~
      |                                                 |
      |                                                 void (*)(zval*, zval*, zval*, void**) {aka void (*)(_zval_struct*, _zval_struct*, _zval_struct*, void**)}
make: *** [Makefile:211: source/opencv2/core/opencv_mat.lo] Error 1
The command '/bin/sh -c cd php-opencv && phpize && ./configure --with-php-config=/usr/bin/php-config && make' returned a non-zero code: 2

now php-opencv supports php 7.4 / 8.0