zmwangx/rust-ffmpeg

[opencv] - conflict between ffmpeg-next and opencv?

Apogeum12 opened this issue · 1 comments

I have a strange issue, when I add ffmpeg-next to Cargo.toml then I can't compile my project. I want to add the ffmpeg feature to a project that uses OpenCV features. Not only that, but I tested all versions of v6 and v5. The error looks like an issue with opencv, but when I remove ffmpeg-next from cargo.toml, OpenCV and the whole project compile successfully. And of course, the app works with opencv.

System info
OS: Ubuntu 23.10 x86_64
Kernel: 6.5.0-14-generic

cargo run
   Compiling clang-sys v1.7.0
   Compiling serde v1.0.195
   Compiling thiserror v1.0.56
   Compiling burn-common v0.11.1
   Compiling num_cpus v1.16.0
   Compiling pin-project v1.1.3
   Compiling flume v0.10.14
   Compiling bindgen v0.64.0
   Compiling clang v2.0.0
   Compiling opencv-binding-generator v0.84.0
   Compiling hashbrown v0.14.3
   Compiling half v2.3.1
   Compiling serde_json v1.0.111
   Compiling bincode v2.0.0-rc.3
   Compiling rmp-serde v1.1.2
   Compiling exr v1.6.4
   Compiling indexmap v2.1.0
   Compiling gpu-descriptor v0.2.4
   Compiling burn-tensor v0.11.1
   Compiling burn-compute v0.11.1
   Compiling text_placeholder v0.5.0
   Compiling naga v0.14.2
   Compiling image v0.24.8
   Compiling ffmpeg-sys-next v6.1.0
   Compiling opencv v0.88.8
error: failed to run custom build command for `opencv v0.88.8`

Caused by:
  process didn't exit successfully: `/home/euuki/github_project/PSU/target/debug/build/opencv-6a31e9357068d0f0/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=OPENCV4_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=OPENCV4_STATIC
  cargo:rerun-if-env-changed=OPENCV4_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=SYSROOT
  cargo:rerun-if-env-changed=OPENCV4_STATIC
  cargo:rerun-if-env-changed=OPENCV4_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=OPENCV4_STATIC
  cargo:rerun-if-env-changed=OPENCV4_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64-unknown-linux-gnu
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_x86_64_unknown_linux_gnu
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:rustc-cfg=ocvrs_opencv_branch_4
  cargo:rerun-if-env-changed=OPENCV_PACKAGE_NAME
  cargo:rerun-if-env-changed=OPENCV_PKGCONFIG_NAME
  cargo:rerun-if-env-changed=OPENCV_CMAKE_NAME
  cargo:rerun-if-env-changed=OPENCV_CMAKE_BIN
  cargo:rerun-if-env-changed=OPENCV_VCPKG_NAME
  cargo:rerun-if-env-changed=OPENCV_LINK_LIBS
  cargo:rerun-if-env-changed=OPENCV_LINK_PATHS
  cargo:rerun-if-env-changed=OPENCV_INCLUDE_PATHS
  cargo:rerun-if-env-changed=OPENCV_DISABLE_PROBES
  cargo:rerun-if-env-changed=OPENCV_MSVC_CRT
  cargo:rerun-if-env-changed=CMAKE_PREFIX_PATH
  cargo:rerun-if-env-changed=OpenCV_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=VCPKG_ROOT
  cargo:rerun-if-env-changed=VCPKGRS_DYNAMIC
  cargo:rerun-if-env-changed=VCPKGRS_TRIPLET
  cargo:rerun-if-env-changed=OCVRS_DOCS_GENERATE_DIR
  cargo:rerun-if-env-changed=DOCS_RS
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/manual-core.cpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/aruco.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/hdf.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/face.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/photo.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/alphamat.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/gapi.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/ocvrs_common.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/sfm.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/videoio.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/ccalib.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/xfeatures2d.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/bioinspired.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/dnn.hpp
  cargo:rerun-if-changed=/home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.88.8/src_cpp/core.hpp
  cargo:rerun-if-changed=Cargo.toml

  --- stderr
  === Crate version: Some("0.88.8")
  === Environment configuration:
  ===   OPENCV_PACKAGE_NAME = None
  ===   OPENCV_PKGCONFIG_NAME = None
  ===   OPENCV_CMAKE_NAME = None
  ===   OPENCV_CMAKE_BIN = None
  ===   OPENCV_VCPKG_NAME = None
  ===   OPENCV_LINK_LIBS = None
  ===   OPENCV_LINK_PATHS = None
  ===   OPENCV_INCLUDE_PATHS = None
  ===   OPENCV_DISABLE_PROBES = None
  ===   OPENCV_MSVC_CRT = None
  ===   CMAKE_PREFIX_PATH = None
  ===   OpenCV_DIR = None
  ===   PKG_CONFIG_PATH = None
  ===   VCPKG_ROOT = None
  ===   VCPKGRS_DYNAMIC = None
  ===   VCPKGRS_TRIPLET = None
  ===   OCVRS_DOCS_GENERATE_DIR = None
  ===   DOCS_RS = None
  ===   PATH = Some("/snap/android-studio/current/jbr/bin:/home/euuki/.bun/bin:/home/euuki/.nvm/versions/node/v18.18.2/bin:/home/euuki/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin")
  === Enabled features:
  ===   ALPHAMAT
  ===   ARUCO
  ===   ARUCO_DETECTOR
  ===   BARCODE
  ===   BGSEGM
  ===   BIOINSPIRED
  ===   CALIB3D
  ===   CCALIB
  ===   CUDAARITHM
  ===   CUDABGSEGM
  ===   CUDACODEC
  ===   CUDAFEATURES2D
  ===   CUDAFILTERS
  ===   CUDAIMGPROC
  ===   CUDAOBJDETECT
  ===   CUDAOPTFLOW
  ===   CUDASTEREO
  ===   CUDAWARPING
  ===   CVV
  ===   DEFAULT
  ===   DNN
  ===   DNN_SUPERRES
  ===   DPM
  ===   FACE
  ===   FEATURES2D
  ===   FLANN
  ===   FREETYPE
  ===   FUZZY
  ===   GAPI
  ===   HDF
  ===   HFS
  ===   HIGHGUI
  ===   IMGCODECS
  ===   IMGPROC
  ===   IMG_HASH
  ===   INTENSITY_TRANSFORM
  ===   LINE_DESCRIPTOR
  ===   MCC
  ===   ML
  ===   OBJDETECT
  ===   OPTFLOW
  ===   OVIS
  ===   PHASE_UNWRAPPING
  ===   PHOTO
  ===   PLOT
  ===   QUALITY
  ===   RAPID
  ===   RGBD
  ===   SALIENCY
  ===   SFM
  ===   SHAPE
  ===   STEREO
  ===   STITCHING
  ===   STRUCTURED_LIGHT
  ===   SUPERRES
  ===   SURFACE_MATCHING
  ===   TEXT
  ===   TRACKING
  ===   VIDEO
  ===   VIDEOIO
  ===   VIDEOSTAB
  ===   VIZ
  ===   WECHAT_QRCODE
  ===   XFEATURES2D
  ===   XIMGPROC
  ===   XOBJDETECT
  ===   XPHOTO
  === Detected probe priority based on environment vars: pkg_config: false, cmake: false, vcpkg: false
  === Probing the OpenCV library in the following order: environment, pkg_config, cmake, vcpkg_cmake, vcpkg
  === Can't probe using: environment, continuing with other methods because: Some environment variables are missing
  === Probing OpenCV library using pkg_config
  === Successfully probed using: pkg_config
  === OpenCV library configuration: Library {
      include_paths: [
          "/usr/include/opencv4",
      ],
      version: Version {
          major: 4,
          minor: 6,
          patch: 0,
      },
      cargo_metadata: [
          "cargo:rustc-link-search=/usr/lib/x86_64-linux-gnu",
          "cargo:rustc-link-lib=opencv_stitching",
          "cargo:rustc-link-lib=opencv_alphamat",
          "cargo:rustc-link-lib=opencv_aruco",
          "cargo:rustc-link-lib=opencv_barcode",
          "cargo:rustc-link-lib=opencv_bgsegm",
          "cargo:rustc-link-lib=opencv_bioinspired",
          "cargo:rustc-link-lib=opencv_ccalib",
          "cargo:rustc-link-lib=opencv_cvv",
          "cargo:rustc-link-lib=opencv_dnn_objdetect",
          "cargo:rustc-link-lib=opencv_dnn_superres",
          "cargo:rustc-link-lib=opencv_dpm",
          "cargo:rustc-link-lib=opencv_face",
          "cargo:rustc-link-lib=opencv_freetype",
          "cargo:rustc-link-lib=opencv_fuzzy",
          "cargo:rustc-link-lib=opencv_hdf",
          "cargo:rustc-link-lib=opencv_hfs",
          "cargo:rustc-link-lib=opencv_img_hash",
          "cargo:rustc-link-lib=opencv_intensity_transform",
          "cargo:rustc-link-lib=opencv_line_descriptor",
          "cargo:rustc-link-lib=opencv_mcc",
          "cargo:rustc-link-lib=opencv_quality",
          "cargo:rustc-link-lib=opencv_rapid",
          "cargo:rustc-link-lib=opencv_reg",
          "cargo:rustc-link-lib=opencv_rgbd",
          "cargo:rustc-link-lib=opencv_saliency",
          "cargo:rustc-link-lib=opencv_shape",
          "cargo:rustc-link-lib=opencv_stereo",
          "cargo:rustc-link-lib=opencv_structured_light",
          "cargo:rustc-link-lib=opencv_phase_unwrapping",
          "cargo:rustc-link-lib=opencv_superres",
          "cargo:rustc-link-lib=opencv_optflow",
          "cargo:rustc-link-lib=opencv_surface_matching",
          "cargo:rustc-link-lib=opencv_tracking",
          "cargo:rustc-link-lib=opencv_highgui",
          "cargo:rustc-link-lib=opencv_datasets",
          "cargo:rustc-link-lib=opencv_text",
          "cargo:rustc-link-lib=opencv_plot",
          "cargo:rustc-link-lib=opencv_ml",
          "cargo:rustc-link-lib=opencv_videostab",
          "cargo:rustc-link-lib=opencv_videoio",
          "cargo:rustc-link-lib=opencv_viz",
          "cargo:rustc-link-lib=opencv_wechat_qrcode",
          "cargo:rustc-link-lib=opencv_ximgproc",
          "cargo:rustc-link-lib=opencv_video",
          "cargo:rustc-link-lib=opencv_xobjdetect",
          "cargo:rustc-link-lib=opencv_objdetect",
          "cargo:rustc-link-lib=opencv_calib3d",
          "cargo:rustc-link-lib=opencv_imgcodecs",
          "cargo:rustc-link-lib=opencv_features2d",
          "cargo:rustc-link-lib=opencv_dnn",
          "cargo:rustc-link-lib=opencv_flann",
          "cargo:rustc-link-lib=opencv_xphoto",
          "cargo:rustc-link-lib=opencv_photo",
          "cargo:rustc-link-lib=opencv_imgproc",
          "cargo:rustc-link-lib=opencv_core",
      ],
  }
  === Detected OpenCV module header dir at: /usr/include/opencv4/opencv2
  === Found OpenCV version: 4.6.0 in headers located at: /usr/include/opencv4
  === Generating code in: /home/euuki/github_project/PSU/target/debug/build/opencv-ffa6eaa96aebeca6/out
  === Placing generated bindings into: /home/euuki/github_project/PSU/target/debug/build/opencv-ffa6eaa96aebeca6/out/opencv
  === Using OpenCV headers from: /usr/include/opencv4
  thread 'main' panicked at /home/euuki/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clang-sys-1.7.0/src/lib.rs:1860:1:
  a `libclang` shared library is not loaded on this thread
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

I don't know why libclang isn't detected(is a installed) with ffmpeg-next in dependencies. This is very strange; this is my first issue like this in RUST and in general, so I don't have much idea how to try to resolve this issue. Maybe someone will have some ideas.

I don't know if this is still an issue, but the same thing happened to me, solution was to specify the "clang-runtime" feature for opencv in cargo.toml
I also have no idea why this happens, but this did the job for me, hope it works for you too!

Edit: I got the solution from a similar issue in opencv, but unfortunately I do not have it at hand.