opencv: OpenCV 4.8.0 build fails with CUDA 12.3, CUDNN 8.9.6.50 on Ubuntu 20.04, undefined references to libffi.so.7.

System Information

OpenCV version: 4.8.0 Operating System / Platform: Ubuntu 20.04 / x86_64 Compiler and compiler version: GCC 9.4.0 Python version: 3.11.5

Detailed description

Build fails at linking due to undefined references to libffi.so.7.

/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_type_float@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_type_double@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_type_void@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_prep_cif@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_type_uint32@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_type_sint32@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_type_sint64@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_call@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_type_pointer@LIBFFI_BASE_7.0'
/usr/bin/ld: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined reference to `ffi_type_uint64@LIBFFI_BASE_7.0'

Attaching full build log. build_log.txt

Steps to reproduce

Using cmake version 3.16.3.

Build command as been some variant of:

make -j32

I’ve attempted to get around this by setting the following system variable beforehand, with no luck:

LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libffi.so.7

Here is the build configuration I’m using, to reproduce:

General configuration for OpenCV 4.8.0-dev =====================================
  Version control:               4.8.0-365-ge95c0055af

  Extra modules:\n"
    Location (extra):            /home/reed/repos/opencv_contrib/modules
    Version control (extra):     4.8.1-37-gd51add39

  Platform:
    Timestamp:                   2023-11-05T15:01:27Z
    Host:                        Linux 5.15.0-88-generic x86_64
    CMake:                       3.16.3
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    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 (9 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (38 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

  C/C++:\n"
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /usr/bin/c++  (ver 9.4.0)
    C++ flags (Release):         -fsigned-char -ffast-math -fno-finite-math-only -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 -ffast-math -fno-finite-math-only -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:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -ffast-math -fno-finite-math-only -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 -ffast-math -fno-finite-math-only -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:                      NO
    Precompiled headers:         NO
    Extra dependencies:          m pthread cudart_static dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn cufft -L/usr/local/cuda/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 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 wechat_qrcode world xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    -
    Disabled by dependency:      -
    Unavailable:                 cvv java julia matlab ovis python2 python2 viz
    Applications:                tests perf_tests apps
    Documentation:               NO
    Non-free algorithms:         YES

  GUI: 
    GTK+:                        YES (ver 3.24.20)
      GThread :                  YES (ver 2.64.6)
      GtkGlExt:                  NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        /home/reed/anaconda3/envs/detr/lib/libz.so (ver 1.2.11)
    JPEG:                        /home/reed/anaconda3/envs/detr/lib/libjpeg.so (ver 80)
    WEBP:                        /home/reed/anaconda3/envs/detr/lib/libwebp.so (ver encoder: 0x020e)
    PNG:                         /home/reed/anaconda3/envs/detr/lib/libpng.so (ver 1.6.37)
    TIFF:                        /home/reed/anaconda3/envs/detr/lib/libtiff.so (ver 42 / 4.1.0)
    JPEG 2000:                   OpenJPEG (ver 2.4.0)
    OpenEXR:                     /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2_3)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:\n"
    DC1394:                      YES (2.2.5)
    FFMPEG:                      YES
      avcodec:                   YES (58.54.100)
      avformat:                  YES (58.29.100)
      avutil:                    YES (56.31.100)
      swscale:                   YES (5.5.100)
      avresample:                YES (4.0.0)
    GStreamer:                   YES (1.16.3)
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            TBB (ver 2020.1 interface 11101)

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:\n"
    Intel IPP:                   2021.10.0 [2021.10.0]
           at:                   /home/reed/repos/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
    Intel IPP IW:                sources (2021.10.0)
              at:                /home/reed/repos/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
    VA:                          NO
    Lapack:                      YES (/home/reed/anaconda3/envs/detr/lib/libmkl_intel_lp64.so /home/reed/anaconda3/envs/detr/lib/libmkl_intel_thread.so /home/reed/anaconda3/envs/detr/lib/libmkl_core.so /home/reed/anaconda3/envs/detr/lib/libiomp5.so -lm -ldl)
    Eigen:                       YES (ver 3.3.7)
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)
    Flatbuffers:                 builtin/3rdparty (23.5.9)

  NVIDIA CUDA:                   YES (ver 12.3, CUFFT CUBLAS FAST_MATH)
    NVIDIA GPU arch:             86
    NVIDIA PTX archs:            90

  cuDNN:                         YES (ver 8.9.6)

  OpenCL:                        YES (no extra features)
    Include path:                /home/reed/repos/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load\n"

  Python 3:\n"
    Interpreter:                 /home/reed/anaconda3/envs/detr/bin/python3 (ver 3.11.5)
    Libraries:                   /home/reed/anaconda3/envs/detr/lib/libpython3.11.so (ver 3.11.5)
    numpy:                       /home/reed/anaconda3/envs/detr/lib/python3.11/site-packages/numpy/core/include (ver 1.26.0)
    install path:                lib/python3.11/site-packages/cv2/python-3.11

  Python (for build):            /usr/bin/python2.7

  Java:                          
    ant:                         NO
    Java:                        NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /usr/local
-----------------------------------------------------------------

Issue submission checklist

  • I report the issue, it’s not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

About this issue

  • Original URL
  • State: closed
  • Created 8 months ago
  • Comments: 19 (4 by maintainers)

Most upvoted comments

Can anybody give the compactable Open-CV and CUDA versions …Please…

@Ambarish-Ombrulla just use all latest versions installed correctly. It should work.

So I got it to work. I had been attempting to use python from an Anaconda environment. Here are the things I did. I stopped doing that and used a virtualenv instead, python 3.11.6. I switched to CUDA 11.8 instead of 12.3. I turned off support for webp and intel ITT in the cmake settings. After that, it built as expected. Besides the errors due to webp and ITT, I think there was a library mismatch or something during build due to that Anaconda env. I may try turning CUDA 12.3 back on in the future.

@Ambarish-Ombrulla Ask on the forum your question is not related to this issue and this issue is closed.

@Ambarish-Ombrulla just use all latest versions installed correctly. It should work.

@shikhindahikar This is currently not correct.

I am using Cuda 12.3 and Opencv 4.9.0 , Using windows 11 and i have been using Cmake GUI and also Terminal Command still not working

@Ambarish-Ombrulla CUDA 12.4 and cuDNN 9.0 are currently not supported.

Use 12.3 and cuDNN 8.9.7 with OpenCV 4.9.0. If you have any build errors raise a question on the forum.

What is the version of Microsoft Visual Studio needed is the any compatible issue with that

Can anybody give the compactable Open-CV and CUDA versions …Please…

Try to turn off the anaconda with ‘conda deactivate’ until (base) disappears. (base) name@pc~$ conda deactivate name@pc~$

I had same problem when using anaconda. (try to install opencv-4.4 at Ubuntu 20.04) When I had problem, the result of cmake .. showed 'Warning’s such as *.so ... may be hidden in {my conda virtual env/lib path}. And then, when I try to build with make -j*, I got same error of yours.

So I tried to turn off anaconda, and such warning and error disappeared with successful build.

No you don’t need latest version. If libglib is 2.64… then u need libffi v2.something. Both should belong to v 2. Check this once if it works.

@Kumataro

A1. I’m only using packages installed via apt/agt-get. This is a fresh install of Ubuntu 20.04, and OpenCV is the first thing I’ve tried to build on it.

A2. From pkg-config, I’m using the following package version for gobject and ffi:

gobject-2.0 v2.64.6 libffi v3.3