0

My project link to opencv lib but the opencv lib my system has depends on libavcodec-* libs. And after I added these libs via target_link_libraries with the correct full path, I also checked some of these symbols, turns out the deps do carry them, but it still complains unresolved symbols provided by these deps, which means the error message remains the same, here are the error messages.

/usr/lib/aarch64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `av_malloc@LIBAVUTIL_FFMPEG_54'
/usr/lib/aarch64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `av_register_all@LIBAVFORMAT_FFMPEG_56'
/usr/lib/aarch64-linux-gnu/libopencv_highgui.so.2.4.9: undefined reference to `avcodec_close@LIBAVCODEC_FFMPEG_56'

I checked the link command by cmake --build . --verbose, its like this:

/usr/bin/c++ \
CMakeFiles/myproject.dir/imgproc.cc.o \
-o \
myproject \
 \
/usr/lib/aarch64-linux-gnu/libQt5Widgets.so.5.6.1 \
/usr/lib/aarch64-linux-gnu/libopencv_features2d.so.2.4.9 \
/usr/lib/aarch64-linux-gnu/libopencv_photo.so.2.4.9 \
_deps/oatpp-build/src/liboatpp.a \
/usr/lib/aarch64-linux-gnu/libavcodec-ffmpeg.so \
/usr/lib/aarch64-linux-gnu/libavformat-ffmpeg.so \
/usr/lib/aarch64-linux-gnu/libavutil-ffmpeg.so \
/usr/lib/aarch64-linux-gnu/libswscale-ffmpeg.so \
/usr/lib/aarch64-linux-gnu/libQt5Gui.so.5.6.1 \
/usr/lib/aarch64-linux-gnu/libQt5Core.so.5.6.1 \
/usr/lib/aarch64-linux-gnu/libopencv_flann.so.2.4.9 \
/usr/lib/aarch64-linux-gnu/libopencv_highgui.so.2.4.9 \
/usr/lib/aarch64-linux-gnu/libopencv_imgproc.so.2.4.9 \
/usr/lib/aarch64-linux-gnu/libopencv_core.so.2.4.9 \
-lpthread \
-latomic

Update: Checked the cv lib and the deps file info.

file /usr/lib/aarch64-linux-gnu/libavcodec-ffmpeg.so.56.60.100 
/usr/lib/aarch64-linux-gnu/libavcodec-ffmpeg.so.56.60.100: ELF 64-bit LSB shared object, ARM aarch64, version 1 (SYSV), dynamically linked, BuildID[sha1]=e534adc24d3ba924851e5a11dc9eee87d5008d36, stripped
file /usr/lib/aarch64-linux-gnu/libopencv_highgui.so.2.4.9 
/usr/lib/aarch64-linux-gnu/libopencv_highgui.so.2.4.9: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=2a6d6bf1318da7a8593b96359b3c8a66008744ee, stripped
  1. Does the version 1 (SYSV) and version 1 (GNU/Linux) have something to do with the link failure?

  2. Preserve libs' order in CMake build (comments)? The cv lib is from find_package but not for the avcodec-ffmpeg, the package does not provide a cmake config, So it's currently from find_library. In CMake how do I get the LINK_LIBS in its order in the link command?

14
  • Probably version mismatch. What nm -D libavcodec-ffmpeg.so | grep avcodec_close tells you? Commented Nov 29, 2023 at 7:04
  • 1
    nm -D /usr/lib/aarch64-linux-gnu/libavcodec-ffmpeg.so | grep avcodec_close 00000000000d4780 T avcodec_close and ll /usr/lib/aarch64-linux-gnu/libavcodec-ffmpeg.so lrwxrwxrwx 1 root root 30 Sep 7 2020 /usr/lib/aarch64-linux-gnu/libavcodec-ffmpeg.so -> libavcodec-ffmpeg.so.56.60.100 seems match? Commented Nov 29, 2023 at 7:07
  • The link order matters, the ffmpeg libraries need to be after the opencv ones. If you use the targets generated by find_package it'll do everything for you. Please show a minimal reproducible example Commented Nov 29, 2023 at 7:21
  • The cv lib is from find_package but not for the avcodec-ffmpeg, the package does not provide a cmake config, So it's currently from find_library Commented Nov 29, 2023 at 7:28
  • if you use the target generated from find_package it should automatically bring in any required dependencies Commented Nov 29, 2023 at 7:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.