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
Does the
version 1 (SYSV)andversion 1 (GNU/Linux)have something to do with the link failure?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?
nm -D libavcodec-ffmpeg.so | grep avcodec_closetells you?nm -D /usr/lib/aarch64-linux-gnu/libavcodec-ffmpeg.so | grep avcodec_close 00000000000d4780 T avcodec_closeandll /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.100seems match?find_packageit'll do everything for you. Please show a minimal reproducible examplefind_packageit should automatically bring in any required dependencies