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

Broken opencv.so on php8-fpm ?

benjy8001 opened this issue · comments

I have an issue wiht php-opencv build on php8 fpm alpine :

Configure stage :

./configure --with-php-config=/usr/bin/php-config8
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... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
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-musl
checking host system type... x86_64-pc-linux-musl
checking target system type... x86_64-pc-linux-musl
checking for PHP prefix... /usr
checking for PHP includes... -I/usr/include/php8 -I/usr/include/php8/main -I/usr/include/php8/TSRM -I/usr/include/php8/Zend -I/usr/include/php8/ext -I/usr/include/php8/ext/date/lib
checking for PHP extension directory... /usr/lib/php8/modules
checking for PHP installed headers prefix... /usr/include/php8
checking if debug is enabled... no
checking if zts is enabled... no
checking for gawk... no
checking for nawk... no
checking for awk... awk
checking if awk 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 for a sed that does not truncate output... /bin/sed
checking for ld used by cc... /usr/x86_64-alpine-linux-musl/bin/ld
checking if the linker (/usr/x86_64-alpine-linux-musl/bin/ld) is GNU ld... yes
checking for /usr/x86_64-alpine-linux-musl/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... 98304
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/x86_64-alpine-linux-musl/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/x86_64-alpine-linux-musl/bin/ld -m elf_x86_64
checking if the linker (/usr/x86_64-alpine-linux-musl/bin/ld -m elf_x86_64) is GNU ld... yes
checking whether the g++ linker (/usr/x86_64-alpine-linux-musl/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/x86_64-alpine-linux-musl/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

Test stage : (witch fail)

make test
/bin/sh /opt/php-opencv/libtool --mode=install cp ./opencv.la /opt/php-opencv/modules
cp ./.libs/opencv.so /opt/php-opencv/modules/opencv.so
cp ./.libs/opencv.lai /opt/php-opencv/modules/opencv.la
PATH="$PATH:/sbin" ldconfig -n /opt/php-opencv/modules
----------------------------------------------------------------------
Libraries have been installed in:
   /opt/php-opencv/modules

If you ever happen to want to link against installed libraries
in a given directory, LIBDIR, you must either use libtool, and
specify the full pathname of the library, or use the `-LLIBDIR'
flag during linking and do at least one of the following:
   - add LIBDIR to the `LD_LIBRARY_PATH' environment variable
     during execution
   - add LIBDIR to the `LD_RUN_PATH' environment variable
     during linking
   - use the `-Wl,--rpath -Wl,LIBDIR' linker flag

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.


=====================================================================
PHP         : /usr/bin/php8 
Fatal error: Internal zvals cannot be refcounted in Unknown on line 0
  
CWD         : /opt/php-opencv
Extra dirs  : 
VALGRIND    : Not used
=====================================================================
TIME START 2021-01-12 10:58:17
=====================================================================
FAIL Check for opencv presence [tests/001.phpt] 
FAIL absdiff function test [tests/absdiff.phpt] 
FAIL CV add function test [tests/add.phpt] 
FAIL Draw circle test [tests/circle.phpt] 
FAIL Check for opencv constant [tests/constant.phpt] 
FAIL CV test [tests/cv.phpt] 
FAIL DNN::blobFromImage [tests/dnn.phpt] 
FAIL Ellipse test [tests/ellipse.phpt] 
FAIL LBPHFaceRecognizer [tests/faceRecognizer.phpt] 
FAIL LBPHFaceRecognizer with Decode [tests/faceRecognizerDecode.phpt] 
FAIL FacemarkLBF::create [tests/facemark.phpt] 
FAIL get_structuring_element function test [tests/get_structuring_element.phpt] 
FAIL CV magnitude function test [tests/magnitude.phpt] 
FAIL Mat __construct [tests/mat.phpt] 
FAIL Exception [tests/opencv_exception.phpt] 
FAIL ROI test [tests/roi.phpt] 
FAIL split test [tests/split.phpt] 
FAIL Type test [tests/type.phpt] 
FAIL CV\VideoCapture Class test [tests/videoCapture.phpt] 
=====================================================================
TIME END 2021-01-12 10:58:18

=====================================================================
TEST RESULT SUMMARY
---------------------------------------------------------------------
Exts skipped    :    0
Exts tested     :    1
---------------------------------------------------------------------

Number of tests :   19                19
Tests skipped   :    0 (  0.0%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :   19 (100.0%) (100.0%)
Tests passed    :    0 (  0.0%) (  0.0%)
---------------------------------------------------------------------
Time taken      :    1 seconds
=====================================================================

=====================================================================
FAILED TEST SUMMARY
---------------------------------------------------------------------
Check for opencv presence [tests/001.phpt]
absdiff function test [tests/absdiff.phpt]
CV add function test [tests/add.phpt]
Draw circle test [tests/circle.phpt]
Check for opencv constant [tests/constant.phpt]
CV test [tests/cv.phpt]
DNN::blobFromImage [tests/dnn.phpt]
Ellipse test [tests/ellipse.phpt]
LBPHFaceRecognizer [tests/faceRecognizer.phpt]
LBPHFaceRecognizer with Decode [tests/faceRecognizerDecode.phpt]
FacemarkLBF::create [tests/facemark.phpt]
get_structuring_element function test [tests/get_structuring_element.phpt]
CV magnitude function test [tests/magnitude.phpt]
Mat __construct [tests/mat.phpt]
Exception [tests/opencv_exception.phpt]
ROI test [tests/roi.phpt]
split test [tests/split.phpt]
Type test [tests/type.phpt]
CV\VideoCapture Class test [tests/videoCapture.phpt]
=====================================================================

You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it.	You can then email it to qa-reports@lists.php.net later.
Do you want to send this report now? [Yns]: n
make: *** [Makefile:132: test] Error 1

Library links :

ldd /usr/lib/php8/modules/opencv.so 
	/lib/ld-musl-x86_64.so.1 (0x7f866603d000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x7f8665e5d000)
	libopencv_world.so.4.5 => /usr/local/lib64//libopencv_world.so.4.5 (0x7f8661978000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7f8661964000)
	libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7f866603d000)
	libz.so.1 => /lib/libz.so.1 (0x7f866194a000)
	libjpeg.so.8 => /usr/lib/libjpeg.so.8 (0x7f86618d0000)
	libpng16.so.16 => /usr/lib/libpng16.so.16 (0x7f86618a0000)
Error relocating /usr/lib/php8/modules/opencv.so: convert_to_long: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_register_long_constant: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: add_index_string: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: _zend_new_array_0: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: rc_dtor_func: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_object_std_dtor: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: convert_to_double: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_call_function: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: _emalloc: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: _zend_new_array: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zval_get_long_func: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: php_info_print_table_header: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: object_init_ex: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_parse_parameters_ex: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_register_string_constant: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: _ecalloc: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: add_next_index_long: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: add_next_index_double: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_exception_get_default: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_declare_property_null: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_declare_property: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: php_info_print_table_end: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_hash_next_index_insert: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: php_info_print_table_start: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_declare_class_constant_long: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_update_property_double: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_register_internal_class: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_strpprintf: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_update_property_long: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_update_property: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_object_std_init: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zval_ptr_dtor: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_parse_parameters: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: object_properties_init: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_register_double_constant: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_register_internal_class_ex: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_throw_exception: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: zend_string_init_interned: symbol not found
Error relocating /usr/lib/php8/modules/opencv.so: std_object_handlers: symbol not found

You compiled in one imge and tryed to use it in another image?

@morozovsk , it's compiled on one image.

Sample file below :

######################
##### Base stage #####
######################

# Base image with alias
FROM php:8-fpm-alpine

ENV APCU_VERSION 5.1.19
ENV TZ=Europe/Paris

RUN apk add --no-cache \
        ca-certificates \
        icu-libs \
        freetype-dev \
        libjpeg-turbo-dev \
        libpng-dev \
        tzdata \
        imagemagick-dev \
        libtool  \
        libxml2-dev \
        ghostscript  \
        imagemagick  \
        zlib-dev \
        libzip-dev && \
    apk add --no-cache --virtual .tools  \
        git \
        unzip \
         && \
    apk add --no-cache --virtual .build-deps  \
        $PHPIZE_DEPS \
        icu-dev \
         && \
    apk update --repository http://dl-cdn.alpinelinux.org/alpine/edge/community && \
    apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community php8-dev && \
    docker-php-ext-install intl \
      zip && \
    pecl install apcu-${APCU_VERSION} && \
    ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
    echo $TZ > /etc/timezone && \
    docker-php-ext-enable apcu && \
    docker-php-ext-enable opcache && \
    docker-php-ext-install mysqli pdo pdo_mysql && \
    docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ && \
    docker-php-ext-install gd && \
    docker-php-ext-install soap && \
    pecl install xdebug && \
    docker-php-ext-enable xdebug && \
    cd /opt && \
    git clone https://github.com/Imagick/imagick && \
    cd imagick && \
    phpize && ./configure && \
    make && \
    make install && \
    cd ..  && \
    apk del .build-deps icu-dev $PHPIZE_DEPS zlib-dev  && \
    apk add gosu --update --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/ --allow-untrusted && \
    addgroup bar && \
    adduser -D -h /home -s /bin/sh -G bar foo

ENV OPENCV_VERSION 4.5.0

RUN apk add --no-cache --virtual .build-deps \
    curl-dev zlib-dev openssl-dev build-base cmake linux-headers git autoconf

# Dl opencv
RUN cd /opt && \
    wget https://github.com/opencv/opencv_contrib/archive/${OPENCV_VERSION}.zip && \
    unzip ${OPENCV_VERSION}.zip && \
    rm ${OPENCV_VERSION}.zip && \
    wget https://github.com/opencv/opencv/archive/${OPENCV_VERSION}.zip && \
    unzip ${OPENCV_VERSION}.zip && \
    rm ${OPENCV_VERSION}.zip

RUN export PKG_CONFIG=/usr/bin/pkg-config && export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig/ && export LD_LIBRARY_PATH="/usr/local/lib64/" && \
  cd /opt/opencv-${OPENCV_VERSION} && \
    mkdir build && cd build && \
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
          -D CMAKE_INSTALL_PREFIX=/usr/local \
          -D WITH_TBB=ON \
          -D WITH_V4L=ON \
          -D INSTALL_C_EXAMPLES=OFF \
          -D INSTALL_PYTHON_EXAMPLES=OFF \
          -D BUILD_PERF_TESTS=OFF \
          -D BUILD_EXAMPLES=OFF \
          -D BUILD_JAVA=OFF \
          -D BUILD_TESTS=OFF \
          -D WITH_QT=OFF \
          -D WITH_FFMPEG=NO \
          -D WITH_OPENGL=ON \
          -D BUILD_opencv_world=ON \
          -D OPENCV_PYTHON_SKIP_DETECTION=ON \
          -D OPENCV_GENERATE_PKGCONFIG=ON \
          -D OPENCV_PC_FILE_NAME=opencv4.pc \
          -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-${OPENCV_VERSION}/modules .. && \
    make -j2 && make install && \
    cd ../.. && \
    rm -R opencv-${OPENCV_VERSION} && \
    rm -R opencv_contrib-${OPENCV_VERSION}

RUN apk update --repository http://dl-cdn.alpinelinux.org/alpine/edge/community && \
  apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/community php8-dev && \
  export PKG_CONFIG=/usr/bin/pkg-config && export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib64/pkgconfig/ && export LD_LIBRARY_PATH="/usr/local/lib64/" && \
    cd /opt && \
    git clone https://github.com/php-opencv/php-opencv.git && \
    cd php-opencv && \
    phpize && \
    ./configure --with-php-config=/usr/bin/php-config8 && \
    make && make install && \
    cd ../ && \
    rm -R php-opencv && \
    apk del php8-dev
    #&& make test

RUN mkdir -p /usr/local/bin/ && \
  mkdir -p /usr/local/lib64/ && \
  mkdir -p /usr/share/OpenCV/ && \
  mkdir -p /usr/local/share/opencv4/ && \
    echo "extension=/usr/lib/php8/modules/opencv.so" > /usr/local/etc/php/conf.d/opencv.ini && \
    echo "extension=/usr/lib/php8/modules/opencv.so" > /etc/php8/conf.d/opencv.ini

RUN ln -s /usr/local/share/opencv4/* /usr/share/OpenCV/

WORKDIR /srv

you have two different binary version of php 8 with different modules.
so you compiled library for one and trying to use with secondary not binary compatible. so that is the reason why you have errors "symbol not found".
screenshot_2021-01-13_01:09:08