Opencv4.5.0 compile error on VIM3

When I want use opencv4.5.0 on VIM3, This error happened.

./…/lib/libopencv_videoio.so.4.5.0: undefined reference to avformat_network_init' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to av_packet_rescale_ts’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to avformat_find_stream_info' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to avcodec_get_name’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to av_frame_unref' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to avformat_new_stream’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to avcodec_receive_packet' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to avformat_close_input’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to av_frame_alloc' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to av_image_fill_arrays’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to av_frame_get_buffer' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to av_opt_set’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to av_frame_free' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to avcodec_open2’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to av_packet_unref' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to av_image_get_buffer_size’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to av_guess_sample_aspect_ratio' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to avcodec_send_frame’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to avformat_get_mov_video_tags' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to av_dict_parse_string’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to avformat_get_riff_video_tags' ../../lib/libopencv_videoio.so.4.5.0: undefined reference to av_packet_free’
…/…/lib/libopencv_videoio.so.4.5.0: undefined reference to `av_packet_alloc’
collect2: error: ld returned 1 exit status
modules/saliency/CMakeFiles/example_saliency_computeSaliency.dir/build.make:102: recipe for target ‘bin/example_saliency_computeSaliency’ failed
make[2]: *** [bin/example_saliency_computeSaliency] Error 1
CMakeFiles/Makefile2:8145: recipe for target ‘modules/saliency/CMakeFiles/example_saliency_computeSaliency.dir/all’ failed
make[1]: *** [modules/saliency/CMakeFiles/example_saliency_computeSaliency.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs…

anyone can help ,thanks.

This is my cmake
cmake -D CMAKE_INSTALL_PREFIX=/usr/local/opencv4.5.0 -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D OPENCV_EXTRA_MODULES_PATH=…/opencv_contrib-4.5.0/modules -D WITH_OPENCL=ON …

Hello @hanshihao

Have you installed the dependencies to build opencv ?

Please try the following steps:

  • Remove pre-installed opencv3 package
$ sudo dpkg -r opencv3
  • Enable apt source in /etc/apt/sources.list

Like this:

--- /etc/apt/sources.list.orig	2020-11-25 16:56:16.834217932 +0800
+++ /etc/apt/sources.list	2020-11-25 16:56:28.078217937 +0800
@@ -1,11 +1,11 @@
 deb http://ports.ubuntu.com/ focal main restricted universe multiverse
-#deb-src http://ports.ubuntu.com/ focal main restricted universe multiverse
+deb-src http://ports.ubuntu.com/ focal main restricted universe multiverse
 
 deb http://ports.ubuntu.com/ focal-security main restricted universe multiverse
-#deb-src http://ports.ubuntu.com/ focal-security main restricted universe multiverse
+deb-src http://ports.ubuntu.com/ focal-security main restricted universe multiverse
 
 deb http://ports.ubuntu.com/ focal-updates main restricted universe multiverse
-#deb-src http://ports.ubuntu.com/ focal-updates main restricted universe multiverse
+deb-src http://ports.ubuntu.com/ focal-updates main restricted universe multiverse
 
 deb http://ports.ubuntu.com/ focal-backports main restricted universe multiverse
-#deb-src http://ports.ubuntu.com/ focal-backports main restricted universe multiverse
+deb-src http://ports.ubuntu.com/ focal-backports main restricted universe multiverse
  • Update source
$ sudo apt update
  • Install opence build dependencies:
$ sudo apt build-dep opencv

After these stpes, try to build your opencv again.

it cannot work,the error also happened.

Maybe still missing some other dependencies, please refer to the opecvc offical ducumentation.

Hello, my problem is like the article. I compile opencv 4.5.3 .

After I finished “sudo apt build-dep opencv”, I still had many error in compiling opencv.

Sometimes stop at 5% or at 10% .
Now, I am compiling that again.

@MingGatsby If you want to use opencv4 , please use this command to intall

$ sudo apt install libopencv-dev python3-opencv

If I install libopencv-dev using apt install , then this library will use software encoder/decoder or hardware ones?
If this version of library uses software components, then how to make it use hardware components?

@vt2022 At present, opencv uses soft solution, and there is no hardware codec support.

Solution to this problem is written about here Compiling OpenCV 4.7.0 - Problems and Solution