OpenCV 4.8.0 Building Failed in Ubuntu 22.02 with CMake : Module RGBD Error

OpenCV version : 4.8.0
Ubuntu version : 22.04
Cmake GUI version : 3.22.1

Building failed history with this version :

  • with OpenGL : ON (previously causing building error until I changed GTK to GTK2)
  • OpenCV module : included (previously causing build error until I disabled BUILD_opencv_xphoto)
  • make -j8 : causing building error until I switch to make only

Current settings :

General configuration for OpenCV 4.8.0 =====================================
  Version control:               unknown

  Extra modules:
    Location (extra):            /home/hiro/Documents/opencv/extra/opencv_contrib-4.x/modules
    Version control (extra):     unknown

    Timestamp:                   2023-11-09T18:46:20Z
    Host:                        Linux 6.2.0-36-generic x86_64
    CMake:                       3.22.1
    CMake generator:             Unix Makefiles
    CMake build tool:            /bin/gmake
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (18 files):         + SSSE3 SSE4_1
      SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (8 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (37 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /bin/c++  (ver 11.4.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
    Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
    ccache:                      YES
    Precompiled headers:         NO
    Extra dependencies:          m pthread cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cufft -L/usr/local/cuda-11.8/lib64 -L/usr/lib/x86_64-linux-gnu
    3rdparty dependencies:

  OpenCV modules:
    To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform java line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab viz wechat_qrcode xfeatures2d ximgproc xobjdetect
    Disabled:                    world xphoto
    Disabled by dependency:      -
    Unavailable:                 cvv julia matlab ovis python2
    Applications:                tests perf_tests apps
    Documentation:               NO
    Non-free algorithms:         YES

  GUI:                           GTK2
    GTK+:                        YES (ver 2.24.33)
      GThread :                  YES (ver 2.72.4)
      GtkGlExt:                  YES (ver 1.2.0)
    OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/
    VTK support:                 YES (ver 9.1.0)

  Media I/O: 
    ZLib:                        /usr/lib/x86_64-linux-gnu/ (ver 1.2.11)
    JPEG:                        /usr/lib/x86_64-linux-gnu/ (ver 80)
    WEBP:                        /usr/lib/x86_64-linux-gnu/ (ver encoder: 0x020f)
    PNG:                         /usr/lib/x86_64-linux-gnu/ (ver 1.6.37)
    TIFF:                        /usr/lib/x86_64-linux-gnu/ (ver 42 / 4.3.0)
    JPEG 2000:                   OpenJPEG (ver 2.4.0)
    OpenEXR:                     /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ (ver 2_5)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      YES (2.2.6)
    FFMPEG:                      YES
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                NO
    GStreamer:                   YES (1.20.3)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            TBB (ver 2021.5 interface 11102)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2021.8 [2021.8.0]
           at:                   /home/hiro/Documents/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
    Intel IPP IW:                sources (2021.8.0)
              at:                /home/hiro/Documents/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
    VA:                          YES
    Lapack:                      YES (/usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/ /usr/lib/x86_64-linux-gnu/
    Eigen:                       YES (ver 3.4.0)
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)
    Flatbuffers:                 builtin/3rdparty (23.5.9)

  NVIDIA CUDA:                   YES (ver 11.8, CUFFT CUBLAS)
    NVIDIA GPU arch:             35 37 50 52 60 61 70 75 80 86 89 90
    NVIDIA PTX archs:

  cuDNN:                         NO

  OpenCL:                        YES (INTELVA)
    Include path:                /home/hiro/Documents/opencv/source/opencv-4.8.0/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 /bin/python3 (ver 3.10.12)
    Libraries:                   /usr/lib/x86_64-linux-gnu/ (ver 3.10.12)
    numpy:                       /home/hiro/.local/lib/python3.10/site-packages/numpy/core/include (ver 1.22.4)
    install path:                lib/python3.10/dist-packages/cv2/python-3.10

  Python (for build):            /bin/python3

    ant:                         /bin/ant (ver 1.10.12)
    Java:                        NO
    JNI:                         /usr/lib/jvm/java-18-openjdk-amd64/include /usr/lib/jvm/java-18-openjdk-amd64/include/linux /usr/lib/jvm/java-18-openjdk-amd64/include
    Java wrappers:               YES (ANT)
    Java tests:                  YES

OpenCV failed to find CuDNN and Java is written as NO for some reason. For information :

nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

CuDNN version is 8.9.6 from tar source.
Previously installed using .deb package but OpenCV failed to find it as well.

java -version  
openjdk version "18.0.2-ea" 2022-07-19
OpenJDK Runtime Environment (build 18.0.2-ea+9-Ubuntu-222.04)
OpenJDK 64-Bit Server VM (build 18.0.2-ea+9-Ubuntu-222.04, mixed mode, sharing)
ant -version
Apache Ant(TM) version 1.10.12

Error : no matching function error

[ 57%] Building CXX object modules/rgbd/CMakeFiles/opencv_rgbd.dir/src/fast_icp.cpp.o                                                                       
/home/hiro/Documents/opencv/extra/opencv_contrib-4.x/modules/rgbd/src/fast_icp.cpp: In member function ‘virtual void cv::kinfu::GetAbInvoker::operator()(
const cv::Range&) const’:                                                                                                                                   
/home/hiro/Documents/opencv/extra/opencv_contrib-4.x/modules/rgbd/src/fast_icp.cpp:242:38: error: no matching function for call to ‘v_and(cv::hal_baselin
e::simd128_cpp::v_float32, cv::hal_baseline::simd128_cpp::v_float32)’                                                                                       
  242 |                 if(!v_check_all(v_and(v_ge(oldCoords, v_setzero_f32()), v_lt(oldCoords, vframe))))                                                  
      |                                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~     
.... (ommited)

/home/hiro/Documents/opencv/source/opencv-4.8.0/modules/core/include/opencv2/core/hal/intrin.hpp:817:5: note: in expansion of macro ‘OPENCV_HAL_WRAP_BIN_
  817 |     OPENCV_HAL_WRAP_BIN_OP_LOGIC(v_int64)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/hiro/Documents/opencv/extra/opencv_contrib-4.x/modules/rgbd/src/fast_icp.cpp:312:38: error: no matching function for call to ‘v_or(cv::hal_baseline
::v_float32x4&, cv::hal_baseline::v_float32x4)’
  312 |                 v_float32x4 vd = v_or(VxNv, v_float32x4(0, 0, 0, dotp));
In file included from /home/hiro/Documents/opencv/extra/opencv_contrib-4.x/modules/rgbd/src/precomp.hpp:22,
                 from /home/hiro/Documents/opencv/extra/opencv_contrib-4.x/modules/rgbd/src/fast_icp.cpp:7:

.... (ommited)

make[2]: *** [modules/rgbd/CMakeFiles/opencv_rgbd.dir/build.make:197: modules/rgbd/CMakeFiles/opencv_rgbd.dir/src/fast_icp.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:7338: modules/rgbd/CMakeFiles/opencv_rgbd.dir/all] Error 2
make: *** [Makefile:166: all] Error 2

Any suggestion ?

Not really, I experianced a similar issue with previous versions of OpenCV so if it was me I would just confirm that I have matching versions of OpenCV from both the main and contrib repositories and if that didn’t work I would disable rgbd and to check if the build is successful without it.

Where did you install it? If you placed it in


then it should have been picked up.

The contrib zip file is from their gitthub written like this : opencv_contrib-4.x
I believe it’s compatible with all openCV version 4, but I might be wrong.

Where did you install it?

This is from my command history. I think it’s aready correct.

sudo cp -P include/cudnn.h /usr/local/cuda-11.8/include   
sudo cp -P lib/libcudnn* /usr/local/cuda-11.8/lib64/  
sudo chmod a+r /usr/local/cuda-11.8/include/cudnn.h /usr/local/cuda-11.8/lib64/libcudnn*

How did you end up installing opencv ? I’m considering installing older version (maybe 4.6 or even 4.5), would like some input on this.

the contrib modules are at latest master, so your main opencv needs to be at the exact same version, too.

the error seems to expect some updated ‘universal simd’ instructions, which are not present in your 4.8.0 main repo. so either:

  • update the main repo to latest master, or,
  • git checkout the contrib one at 4.8.0 (same as your main repo)

cleanup all & restart cmake / make

1 Like

I’m an idiot, I’m downloading contrib 4.8.0 right away and building my opencv right now. I’ll update my comment / post about the results.

You need to copy all the headers to be on the safe side when building but for configuration you need both

  • cudnn.h
  • cudnn_version.h

I’m on my way building. Could you please you elaborate more on this ?

“all the headers to be on the safe side”

What is “the safe side” ? You also mentioned for configuration you need “both”, what “both” ? What information am I supposed pay attention at from the FindCUDNN.cmake code above ? I am extremely confused, please enlighten me my good sir :slightly_frowning_face:

I mean to be 100% sure that OpenCV will be able to find all the cudnn headers that it requires when you build. Its safe because all the headers will be in the correct location. The alternative would be to copy only a subset of headers which may result in the configuration working but at build time you may be missing a required header.

Don’t worry about it that is just for reference if you are interested. The take home is you only copied accross cudnn.h and for the configuration stage to pick up cuDNN you require both cudnn.h and cudnn_version.h (shown in the links above to FindCUDNN.cmake). Additionaly when you build you may require more headers so to be safe/certain/assured that the build will work you want to do

sudo cp -P include/* /usr/local/cuda-11.8/include

Hello !
I followed your instruction to copy all of the headers, OpenCV could read my CuDNN ! After building about 63%, it still failed due to rgbd module so I disabled rgbd module and my OpenCV building succeed after 6-7 hours. Thank you so much !

I have one last things I need advice on, I didnt set the Generate OpenCV PKGCONFIG = ON (I wasn’t aware), so now I can’t read OpenCV header. I really don’t want to rebuild for 6 hours. Is there anyway around this ?

If you are using CMake in your project you can pass -DOpenCV_DIR= at the configuration stage, or you could try re-configuring CMake for OpenCV by passing -DOpenCV PKGCONFIG=ON keeping the rest of the arguments the same and hoping that it doesn’t re-build everything.

Unfortunately I will not be using cmake for the project. Also I tried to re-configure everything with PKCONFIG=ON but the opencv4.pc file did not get generated. I think it’ll get generated at the very end step during building. Just in case there was no other way, I’ve been building it again anyway since my last message, so it’s been 4 hours now and it’s still at 27%. :slightly_frowning_face:

However my original problem with building error is solved and you helped me find CuDNN, thank you so much and have a great weekend !

That’s unfortunate. Have you tried selecting only the GPU architectures that you require with -DCUDA_ARCH_BIN=. Its a shame you were getting errors with -j as I can easily build in under an hour with -j 20 on my i7-12700H which supposedly has 20 logical processors.

After 8h finally building is done and I have installed it. PKGCONFIG is there. I could confirm my opencv installation it by running :

pkg-config --libs opencv4

I’ve been struggling with a new thing now, that my simplest code can never seems to find opencv despite including opencv libraries and setting my ld library path. It’s out of topic of this question so maybe it’s not the right place to put it here. It’s been a journey, I hope it gets smoother from here for me.

nvm everything works now ! congratulation for me i guess. Thanks again for your help and input !

1 Like