opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
79.15k stars 55.83k forks source link

opencv build failed on the ubuntu 22.04 #23267

Closed vndroid closed 1 year ago

vndroid commented 1 year ago

System Information

OpenCV version: 2.4.13.7 Operating System / Platform: Ubuntu 22.04 Compiler & compiler version: GCC 11.3.0

Detailed description

Build log

[  4%] Built target libjasper
Consolidate compiler generated dependencies of target IlmImf
[  4%] Building CXX object 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfAcesFile.cpp.o
cc1plus: warning: command-line option ‘-Wmissing-prototypes’ is valid for C/ObjC but not for C++
cc1plus: warning: command-line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
In file included from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfHeader.h:51,
                 from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfAcesFile.h:80,
                 from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfAcesFile.cpp:41:
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:227:41: error: ISO C++17 does not allow dynamic exception specifications
  227 |     const Vec2 &        normalizeExc () throw (Iex::MathExc);
      |                                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:231:48: error: ISO C++17 does not allow dynamic exception specifications
  231 |     Vec2<T>             normalizedExc () const throw (Iex::MathExc);
      |                                                ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:439:41: error: ISO C++17 does not allow dynamic exception specifications
  439 |     const Vec3 &        normalizeExc () throw (Iex::MathExc);
      |                                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:443:48: error: ISO C++17 does not allow dynamic exception specifications
  443 |     Vec3<T>             normalizedExc () const throw (Iex::MathExc);
      |                                                ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:621:37: error: ISO C++17 does not allow dynamic exception specifications
  621 |     const Vec4 &    normalizeExc () throw (Iex::MathExc);
      |                                     ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:625:44: error: ISO C++17 does not allow dynamic exception specifications
  625 |     Vec4<T>         normalizedExc () const throw (Iex::MathExc);
      |                                            ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:713:30: error: ISO C++17 does not allow dynamic exception specifications
  713 | Vec2<short>::normalizeExc () throw (Iex::MathExc);
      |                              ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:722:37: error: ISO C++17 does not allow dynamic exception specifications
  722 | Vec2<short>::normalizedExc () const throw (Iex::MathExc);
      |                                     ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:737:28: error: ISO C++17 does not allow dynamic exception specifications
  737 | Vec2<int>::normalizeExc () throw (Iex::MathExc);
      |                            ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:746:35: error: ISO C++17 does not allow dynamic exception specifications
  746 | Vec2<int>::normalizedExc () const throw (Iex::MathExc);
      |                                   ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:761:30: error: ISO C++17 does not allow dynamic exception specifications
  761 | Vec3<short>::normalizeExc () throw (Iex::MathExc);
      |                              ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:770:37: error: ISO C++17 does not allow dynamic exception specifications
  770 | Vec3<short>::normalizedExc () const throw (Iex::MathExc);
      |                                     ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:785:28: error: ISO C++17 does not allow dynamic exception specifications
  785 | Vec3<int>::normalizeExc () throw (Iex::MathExc);
      |                            ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:794:35: error: ISO C++17 does not allow dynamic exception specifications
  794 | Vec3<int>::normalizedExc () const throw (Iex::MathExc);
      |                                   ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:808:30: error: ISO C++17 does not allow dynamic exception specifications
  808 | Vec4<short>::normalizeExc () throw (Iex::MathExc);
      |                              ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:817:37: error: ISO C++17 does not allow dynamic exception specifications
  817 | Vec4<short>::normalizedExc () const throw (Iex::MathExc);
      |                                     ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:832:28: error: ISO C++17 does not allow dynamic exception specifications
  832 | Vec4<int>::normalizeExc () throw (Iex::MathExc);
      |                            ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:841:35: error: ISO C++17 does not allow dynamic exception specifications
  841 | Vec4<int>::normalizedExc () const throw (Iex::MathExc);
      |                                   ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:1211:26: error: ISO C++17 does not allow dynamic exception specifications
 1211 | Vec2<T>::normalizeExc () throw (Iex::MathExc)
      |                          ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:1248:33: error: ISO C++17 does not allow dynamic exception specifications
 1248 | Vec2<T>::normalizedExc () const throw (Iex::MathExc)
      |                                 ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:1703:26: error: ISO C++17 does not allow dynamic exception specifications
 1703 | Vec3<T>::normalizeExc () throw (Iex::MathExc)
      |                          ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:1742:33: error: ISO C++17 does not allow dynamic exception specifications
 1742 | Vec3<T>::normalizedExc () const throw (Iex::MathExc)
      |                                 ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:2108:26: error: ISO C++17 does not allow dynamic exception specifications
 2108 | Vec4<T>::normalizeExc () throw (Iex::MathExc)
      |                          ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathVec.h:2149:33: error: ISO C++17 does not allow dynamic exception specifications
 2149 | Vec4<T>::normalizedExc () const throw (Iex::MathExc)
      |                                 ^~~~~
In file included from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfRgba.h:45,
                 from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfAcesFile.h:81,
                 from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfAcesFile.cpp:41:
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Half/half.h: In constructor ‘half::half(float)’:
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Half/half.h:471:18: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
  471 |     register int e = (x.i >> 23) & 0x000001ff;
      |                  ^
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Half/half.h:482:22: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
  482 |         register int m = x.i & 0x007fffff;
      |                      ^
In file included from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfChromaticities.h:47,
                 from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfChromaticitiesAttribute.h:47,
                 from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfStandardAttributes.h:58,
                 from /home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfAcesFile.cpp:43:
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h: At global scope:
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:265:25: error: ISO C++17 does not allow dynamic exception specifications
  265 |                         throw (Iex::MathExc);
      |                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:268:25: error: ISO C++17 does not allow dynamic exception specifications
  268 |                         throw (Iex::MathExc);
      |                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:271:25: error: ISO C++17 does not allow dynamic exception specifications
  271 |                         throw (Iex::MathExc);
      |                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:274:25: error: ISO C++17 does not allow dynamic exception specifications
  274 |                         throw (Iex::MathExc);
      |                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:639:25: error: ISO C++17 does not allow dynamic exception specifications
  639 |                         throw (Iex::MathExc);
      |                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:642:25: error: ISO C++17 does not allow dynamic exception specifications
  642 |                         throw (Iex::MathExc);
      |                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:645:25: error: ISO C++17 does not allow dynamic exception specifications
  645 |                         throw (Iex::MathExc);
      |                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:648:25: error: ISO C++17 does not allow dynamic exception specifications
  648 |                         throw (Iex::MathExc);
      |                         ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:1432:38: error: ISO C++17 does not allow dynamic exception specifications
 1432 | Matrix33<T>::gjInvert (bool singExc) throw (Iex::MathExc)
      |                                      ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:1440:45: error: ISO C++17 does not allow dynamic exception specifications
 1440 | Matrix33<T>::gjInverse (bool singExc) const throw (Iex::MathExc)
      |                                             ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:1544:36: error: ISO C++17 does not allow dynamic exception specifications
 1544 | Matrix33<T>::invert (bool singExc) throw (Iex::MathExc)
      |                                    ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:1552:43: error: ISO C++17 does not allow dynamic exception specifications
 1552 | Matrix33<T>::inverse (bool singExc) const throw (Iex::MathExc)
      |                                           ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h: In static member function ‘static void Imath::Matrix44<T>::multiply(const Imath::Matrix44<T>&, const Imath::Matrix44<T>&, Imath::Matrix44<T>&)’:
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2529:39: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2529 |     register const T * IMATH_RESTRICT ap = &a.x[0][0];
      |                                       ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2530:39: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2530 |     register const T * IMATH_RESTRICT bp = &b.x[0][0];
      |                                       ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2531:39: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2531 |     register       T * IMATH_RESTRICT cp = &c.x[0][0];
      |                                       ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2533:16: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2533 |     register T a0, a1, a2, a3;
      |                ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2533:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2533 |     register T a0, a1, a2, a3;
      |                    ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2533:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2533 |     register T a0, a1, a2, a3;
      |                        ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2533:28: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2533 |     register T a0, a1, a2, a3;
      |                            ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h: At global scope:
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2701:38: error: ISO C++17 does not allow dynamic exception specifications
 2701 | Matrix44<T>::gjInvert (bool singExc) throw (Iex::MathExc)
      |                                      ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2709:45: error: ISO C++17 does not allow dynamic exception specifications
 2709 | Matrix44<T>::gjInverse (bool singExc) const throw (Iex::MathExc)
      |                                             ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2813:36: error: ISO C++17 does not allow dynamic exception specifications
 2813 | Matrix44<T>::invert (bool singExc) throw (Iex::MathExc)
      |                                    ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2821:43: error: ISO C++17 does not allow dynamic exception specifications
 2821 | Matrix44<T>::inverse (bool singExc) const throw (Iex::MathExc)
      |                                           ^~~~~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h: In instantiation of ‘static void Imath::Matrix44<T>::multiply(const Imath::Matrix44<T>&, const Imath::Matrix44<T>&, Imath::Matrix44<T>&) [with T = float]’:
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2519:14:   required from ‘Imath::Matrix44<T> Imath::Matrix44<T>::operator*(const Imath::Matrix44<T>&) const [with T = float]’
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/IlmImf/ImfAcesFile.cpp:458:26:   required from here
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2529:39: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2529 |     register const T * IMATH_RESTRICT ap = &a.x[0][0];
      |                                       ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2530:39: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2530 |     register const T * IMATH_RESTRICT bp = &b.x[0][0];
      |                                       ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2531:39: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2531 |     register       T * IMATH_RESTRICT cp = &c.x[0][0];
      |                                       ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2533:16: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2533 |     register T a0, a1, a2, a3;
      |                ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2533:20: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2533 |     register T a0, a1, a2, a3;
      |                    ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2533:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2533 |     register T a0, a1, a2, a3;
      |                        ^~
/home/kane/Desktop/src/opencv-2.4.13.7/3rdparty/openexr/Imath/ImathMatrix.h:2533:28: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
 2533 |     register T a0, a1, a2, a3;
      |                            ^~
make[2]: *** [3rdparty/openexr/CMakeFiles/IlmImf.dir/build.make:118: 3rdparty/openexr/CMakeFiles/IlmImf.dir/IlmImf/ImfAcesFile.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:1475: 3rdparty/openexr/CMakeFiles/IlmImf.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

the error is similar, such as

error: ISO C++17 does not allow dynamic exception specifications
...

Steps to reproduce

according to the official doc: opencv

wget https://github.com/opencv/opencv/archive/refs/tags/2.4.13.7.tar.gz
tar xf 2.4.13.7.tar.gz
cd opencv-2.4.13.7/
mkdir build
cd build/
cmake -D CMAKE_BUILD_TYPE=RELEASE ..

Can see some warning info:

CMake Warning at cmake/OpenCVPackaging.cmake:23 (message):
  CPACK_PACKAGE_VERSION does not match version provided by version.hpp
  header!
Call Stack (most recent call first):
  CMakeLists.txt:1103 (include)

edit the CMake file (## line is comment)

vim ../cmake/OpenCVPackaging.cmake
## At the first OPENCV_VCSVERSION Add the definition.
set(OPENCV_VCSVERSION "2.4.13.7")
## recmake and build
cmake -D CMAKE_BUILD_TYPE=RELEASE ..
make -j8
sudo make install

Issue submission checklist

asmorkalov commented 1 year ago

OpenCV version: 2.4.13.7 - it very old version. I was release many years before C++17 and is not supported by OpenCV team. Please use modern Library version (3.4.19 or 4.7.0).

vndroid commented 1 year ago

OpenCV version: 2.4.13.7 - it very old version. I was release many years before C++17 and is not supported by OpenCV team. Please use modern Library version (3.4.19 or 4.7.0).

Yep, I already know it is too old, but I use it to build the VideoLAN, the 3.x and 4.x opencv can not be used in the vlc.

berak commented 1 year ago

@vndroid you won't need HDR images support for VideoLan, so try to use

-DWITH_OPENEXR=OFF -DBUILD_OPENEXR=OFF

cmake flags , to disable it

Kumataro commented 1 year ago

Another possibility is to tell GCC to compile with the C++98 Standard via CMAKE options.

cmake ../ -DCMAKE_CXX_STANDARD=98 \
               -DCMAKE_CXX_STANDARD_REQUIRED=ON \
               -DCMAKE_CXX_EXTENSION=OFF
make -j 12

These CMAKE parametes request upper CMake 3.1.

OpenCV 4.x uses these parameters to apply C++11.

https://github.com/opencv/opencv/blob/ca48e217f1be1f77efc0a8e684d42b7ac899053d/cmake/OpenCVDetectCXXCompiler.cmake#L201-L208

dkurt commented 1 year ago

Hi! I were able to compile VLC with the latest OpenCV and the following changes. Note that I have not tested how it works yet.

--- a/modules/core/include/opencv2/core/cvdef.h
+++ b/modules/core/include/opencv2/core/cvdef.h
@@ -778,14 +778,16 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ   (EnumType, EnumType)
 #    undef CV_CXX11
 #  endif
 #endif
-#ifndef CV_CXX11
+#if defined(__cplusplus) && !defined(CV_CXX11)
 #  error "OpenCV 4.x+ requires enabled C++11 support"
 #endif

+#ifdef __cplusplus
 #define CV_CXX_MOVE_SEMANTICS 1
 #define CV_CXX_MOVE(x) std::move(x)
 #define CV_CXX_STD_ARRAY 1
 #include <array>
+#endif
 #ifndef CV_OVERRIDE
 #  define CV_OVERRIDE override
 #endif

VLC patch:

--- a/configure.ac
+++ b/configure.ac
@@ -2069,7 +2069,7 @@ PKG_ENABLE_MODULES_VLC([BLURAY], [libbluray], [libbluray >= 0.6.2], (libbluray f
 dnl
 dnl  OpenCV wrapper and example filters
 dnl
-PKG_ENABLE_MODULES_VLC([OPENCV], [opencv_example opencv_wrapper], [opencv > 2.0], (OpenCV (computer vision) filter), [auto])
+PKG_ENABLE_MODULES_VLC([OPENCV], [opencv_example opencv_wrapper], [opencv4], (OpenCV (computer vision) filter), [auto])
opencv_example.cpp which should be reworked ```patch --- a/modules/video_filter/opencv_example.cpp +++ b/modules/video_filter/opencv_example.cpp @@ -128,7 +128,7 @@ static int OpenFilter( vlc_object_t *p_this ) //OpenCV init specific to this example char* filename = var_InheritString( p_filter, "opencv-haarcascade-file" ); - p_sys->p_cascade = (CvHaarClassifierCascade*)cvLoad( filename, 0, 0, 0 ); + // p_sys->p_cascade = (CvHaarClassifierCascade*)cvLoad( filename, 0, 0, 0 ); p_sys->p_storage = cvCreateMemStorage(0); free( filename ); @@ -142,8 +142,8 @@ static void CloseFilter( filter_t *p_filter ) { filter_sys_t *p_sys = static_cast(p_filter->p_sys); - if( p_sys->p_cascade ) - cvReleaseHaarClassifierCascade( &p_sys->p_cascade ); + // if( p_sys->p_cascade ) + // cvReleaseHaarClassifierCascade( &p_sys->p_cascade ); if( p_sys->p_storage ) cvReleaseMemStorage( &p_sys->p_storage ); @@ -184,39 +184,40 @@ static picture_t *Filter( filter_t *p_filter, picture_t *p_pic ) if( p_sys->p_cascade ) { //we should make some of these params config variables - CvSeq *faces = cvHaarDetectObjects( p_img[0], p_sys->p_cascade, - p_sys->p_storage, 1.15, 5, - CV_HAAR_DO_CANNY_PRUNING, - cvSize(20, 20) ); + // CvSeq *faces = 0; + // CvSeq *faces = cvHaarDetectObjects( p_img[0], p_sys->p_cascade, + // p_sys->p_storage, 1.15, 5, + // CV_HAAR_DO_CANNY_PRUNING, + // cvSize(20, 20) ); //create the video_filter_region_info_t struct - if (faces && (faces->total > 0)) - { - //msg_Dbg( p_filter, "Found %d face(s)", faces->total ); - free( p_sys->event_info.p_region ); - p_sys->event_info.p_region = (video_filter_region_info_t*) - calloc( faces->total, sizeof(video_filter_region_info_t)); - if( !p_sys->event_info.p_region ) - return NULL; - p_sys->event_info.i_region_size = faces->total; - } - - //populate the video_filter_region_info_t struct - for( int i = 0; i < (faces ? faces->total : 0); i++ ) - { - CvRect *r = (CvRect*)cvGetSeqElem( faces, i ); - pt1.x = r->x*scale; - pt2.x = (r->x+r->width)*scale; - pt1.y = r->y*scale; - pt2.y = (r->y+r->height)*scale; - cvRectangle( p_img[0], pt1, pt2, CV_RGB(0,0,0), 3, 8, 0 ); - - *(CvRect*)(&(p_sys->event_info.p_region[i])) = *r; - p_sys->event_info.p_region[i].i_id = p_sys->i_id++; - p_sys->event_info.p_region[i].p_description = "Face Detected"; - } - - if (faces && (faces->total > 0)) //raise the video filter event - var_TriggerCallback( vlc_object_instance(p_filter), VIDEO_FILTER_EVENT_VARIABLE ); + // if (faces && (faces->total > 0)) + // { + // //msg_Dbg( p_filter, "Found %d face(s)", faces->total ); + // free( p_sys->event_info.p_region ); + // p_sys->event_info.p_region = (video_filter_region_info_t*) + // calloc( faces->total, sizeof(video_filter_region_info_t)); + // if( !p_sys->event_info.p_region ) + // return NULL; + // p_sys->event_info.i_region_size = faces->total; + // } + // + // //populate the video_filter_region_info_t struct + // for( int i = 0; i < (faces ? faces->total : 0); i++ ) + // { + // CvRect *r = (CvRect*)cvGetSeqElem( faces, i ); + // pt1.x = r->x*scale; + // pt2.x = (r->x+r->width)*scale; + // pt1.y = r->y*scale; + // pt2.y = (r->y+r->height)*scale; + // cvRectangle( p_img[0], pt1, pt2, CV_RGB(0,0,0), 3, 8, 0 ); + // + // *(CvRect*)(&(p_sys->event_info.p_region[i])) = *r; + // p_sys->event_info.p_region[i].i_id = p_sys->i_id++; + // p_sys->event_info.p_region[i].p_description = "Face Detected"; + // } + // + // if (faces && (faces->total > 0)) //raise the video filter event + // var_TriggerCallback( vlc_object_instance(p_filter), VIDEO_FILTER_EVENT_VARIABLE ); } else msg_Err( p_filter, "No cascade - is opencv-haarcascade-file valid?" ); ```
dkurt commented 1 year ago

@opencv-alalek, @mshabunin, what is your opinion about this workaround?

I'm trying to understand on this minimal example:

// main.c
#include <opencv2/core/core_c.h>

int main(int argc, char** argv) {
    CvMat* inp = cvCreateMatHeader(256 * 256, 1, CV_32FC2);
    CvMat* out = cvCreateMatHeader(256 * 256, 1, CV_32FC2);
    cvCreateData(inp);
    cvCreateData(out);
    cvDFT(inp, out, CV_DXT_FORWARD, 0);
    cvReleaseData(inp);
    cvReleaseData(out);
    return 0;
}

If I compile with one of the following flags, there is an error:

gcc main.c -o app -I/home/dkurt/opencv_install/include/opencv4/ -lopencv_core -L/home/dkurt/opencv_install/lib/
gcc main.c -o app -I/home/dkurt/opencv_install/include/opencv4/ -lopencv_core -L/home/dkurt/opencv_install/lib/ -O2
In file included from /home/dkurt/opencv_install/include/opencv4/opencv2/core/types_c.h:84,
                 from /home/dkurt/opencv_install/include/opencv4/opencv2/core/core_c.h:48,
                 from main.c:1:
/home/dkurt/opencv_install/include/opencv4/opencv2/core/cvdef.h:783:4: error: #error "OpenCV 4.x+ requires enabled C++11 support"
  783 | #  error "OpenCV 4.x+ requires enabled C++11 support"
      |    ^~~~~
/home/dkurt/opencv_install/include/opencv4/opencv2/core/cvdef.h:790:10: fatal error: array: No such file or directory
  790 | #include <array>
      |          ^~~~~~~
compilation terminated.

However with this patch and -O2 I'm able to compile and run the app.

--- a/modules/core/include/opencv2/core/cvdef.h
+++ b/modules/core/include/opencv2/core/cvdef.h
@@ -778,14 +778,16 @@ __CV_ENUM_FLAGS_BITWISE_XOR_EQ   (EnumType, EnumType)
 #    undef CV_CXX11
 #  endif
 #endif
-#ifndef CV_CXX11
+#if defined(__cplusplus) && !defined(CV_CXX11)
 #  error "OpenCV 4.x+ requires enabled C++11 support"
 #endif

+#ifdef __cplusplus
 #define CV_CXX_MOVE_SEMANTICS 1
 #define CV_CXX_MOVE(x) std::move(x)
 #define CV_CXX_STD_ARRAY 1
 #include <array>
+#endif
 #ifndef CV_OVERRIDE
 #  define CV_OVERRIDE override
 #endif

I don't understand why there is a difference in adding -O2:

$ gcc main.c -o app -I/home/dkurt/opencv_install/include/opencv4/ -lopencv_core -L/home/dkurt/opencv_install/lib/

/usr/local/bin/ld: /tmp/ccwyTyeQ.o: undefined reference to symbol 'lrint@@GLIBC_2.2.5'
/usr/local/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

UPD: Even with -O1 it's compiled fine. GCC 9.4.0 (Ubuntu 20.04)

some problem which sounds similar: https://stackoverflow.com/questions/30514416/gcc-links-to-wrong-glibcxx-version-when-o2-flag-is-specified

nm --demangle /home/dkurt/opencv_install/lib/libopencv_core.so | grep GLIBC_2.2.5 ```bash $ nm --demangle /home/dkurt/opencv_install/lib/libopencv_core.so | grep GLIBC_2.2.5 U __cxa_atexit@GLIBC_2.2.5 w __cxa_finalize@GLIBC_2.2.5 U __errno_location@GLIBC_2.2.5 w __pthread_key_create@GLIBC_2.2.5 U __xstat@GLIBC_2.2.5 U abort@GLIBC_2.2.5 U acos@GLIBC_2.2.5 U acosf@GLIBC_2.2.5 U atanf@GLIBC_2.2.5 U ceil@GLIBC_2.2.5 U close@GLIBC_2.2.5 U closedir@GLIBC_2.2.5 U cos@GLIBC_2.2.5 U dladdr@GLIBC_2.2.5 U dlclose@GLIBC_2.2.5 U dlerror@GLIBC_2.2.5 U dlopen@GLIBC_2.2.5 U dlsym@GLIBC_2.2.5 U fclose@GLIBC_2.2.5 U fcntl@GLIBC_2.2.5 U feof@GLIBC_2.2.5 U fflush@GLIBC_2.2.5 U fgetc@GLIBC_2.2.5 U fgets@GLIBC_2.2.5 U floor@GLIBC_2.2.5 U fopen@GLIBC_2.2.5 U fputc@GLIBC_2.2.5 U fputs@GLIBC_2.2.5 U free@GLIBC_2.2.5 U fseek@GLIBC_2.2.5 U ftell@GLIBC_2.2.5 U getcwd@GLIBC_2.2.5 U getenv@GLIBC_2.2.5 U isspace@GLIBC_2.2.5 U log10@GLIBC_2.2.5 U lrint@GLIBC_2.2.5 U lrintf@GLIBC_2.2.5 U malloc@GLIBC_2.2.5 U memcmp@GLIBC_2.2.5 U memmove@GLIBC_2.2.5 U memset@GLIBC_2.2.5 U mkdir@GLIBC_2.2.5 U mkstemp@GLIBC_2.2.5 U open@GLIBC_2.2.5 U opendir@GLIBC_2.2.5 U posix_memalign@GLIBC_2.2.5 U pthread_create@GLIBC_2.2.5 U pthread_getspecific@GLIBC_2.2.5 U pthread_join@GLIBC_2.2.5 U pthread_key_create@GLIBC_2.2.5 U pthread_key_delete@GLIBC_2.2.5 U pthread_mutex_destroy@GLIBC_2.2.5 U pthread_mutex_init@GLIBC_2.2.5 U pthread_mutex_lock@GLIBC_2.2.5 U pthread_mutex_unlock@GLIBC_2.2.5 w pthread_mutexattr_destroy@GLIBC_2.2.5 w pthread_mutexattr_init@GLIBC_2.2.5 w pthread_mutexattr_settype@GLIBC_2.2.5 U pthread_self@GLIBC_2.2.5 U pthread_setspecific@GLIBC_2.2.5 U readdir@GLIBC_2.2.5 U remove@GLIBC_2.2.5 U rewind@GLIBC_2.2.5 U rmdir@GLIBC_2.2.5 U sched_yield@GLIBC_2.2.5 U sin@GLIBC_2.2.5 U sincos@GLIBC_2.2.5 U sinf@GLIBC_2.2.5 U sqrt@GLIBC_2.2.5 U sqrtf@GLIBC_2.2.5 U stderr@GLIBC_2.2.5 U stdout@GLIBC_2.2.5 U strchr@GLIBC_2.2.5 U strcmp@GLIBC_2.2.5 U strcpy@GLIBC_2.2.5 U strdup@GLIBC_2.2.5 U strlen@GLIBC_2.2.5 U strncpy@GLIBC_2.2.5 U strrchr@GLIBC_2.2.5 U strstr@GLIBC_2.2.5 U strtod@GLIBC_2.2.5 U strtol@GLIBC_2.2.5 U strtoull@GLIBC_2.2.5 U sysconf@GLIBC_2.2.5 U tolower@GLIBC_2.2.5 U toupper@GLIBC_2.2.5 U unlink@GLIBC_2.2.5 U wcslen@GLIBC_2.2.5 U wmemcpy@GLIBC_2.2.5 ```

UPD: related MR in VLC: https://code.videolan.org/videolan/vlc/-/merge_requests/927