0

I have a program using OpenCV. I link the library using -L/path/to/opencv/lib flags, and also the path to the library is specified using -Wl,-rpath flag.

For some reason, when running ldd, I see that the links to most of the OpenCV libraries are found(for example opencv_core). However, all the CUDA related libraries(such as opencv_cudaarithm) are not found.

This was fixed when I have added the OpenCV library path to LD_LIBRARY_PATH, but I would have expected it to work without having to change LD_LIBRARY_PATH, especially since the path to some of the libraries is resolved.

Does anyone have an idea what it could be?

Edit: There is no error message The output from ldd before adding OpenCV to LD_LIBRARY_PATH:

libopencv_imgcodecs.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_imgcodecs.so.3.4 (0x00007fcf7acd4000)
libopencv_imgproc.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_imgproc.so.3.4 (0x00007fcf7918e000)
libopencv_core.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_core.so.3.4 (0x00007fcf77fb0000)
libopencv_photo.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_photo.so.3.4 (0x00007fcf77dfe000)
libopencv_cudaimgproc.so.3.4 => not found
libopencv_cudaarithm.so.3.4 => not found

After adding OpenCV:

libopencv_imgcodecs.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_imgcodecs.so.3.4 (0x00007fcf7acd4000)
libopencv_imgproc.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_imgproc.so.3.4 (0x00007fcf7918e000)
libopencv_core.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_core.so.3.4 (0x00007fcf77fb0000)
libopencv_photo.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_photo.so.3.4 (0x00007fcf77dfe000)
libopencv_cudaimgproc.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_cudaimgproc.so.3.4 (0x00007fcf76b03000)
libopencv_cudaarithm.so.3.4 => /usr/Local/opencv/v.3.4.13/lib/libopencv_cudaarithm.so.3.4 (0x00007fcf74bed000)
  • Showing the _actual_ link line, the error message, and the output from `ldd` (with and without setting `LD_LIBRARY_PATH`) would probably help giving you correct answer. I _suspect_ I know the answer, but don't want to speculate without additional info. – Employed Russian Apr 10 '23 at 01:17
  • 1
    I've added the output as an edit to the question – Arik Vasserman Apr 18 '23 at 13:58

1 Answers1

0

As this answer explains, using -rpath=... only affects the direct dependencies from the main executable, but not transitive dependencies from one DSO on another.

You could fix this issue in one of two ways:

  1. Add -Wl,--disable-new-dtags to your link line. That should change DT_RUNPATH to DT_RPATH (use readelf -d your-exe to confirm), which would make the -rpath setting have a global effect.
  2. Add direct dependencies on libopencv_cudaimgproc and libopencv_cudaarithm to the executable itself, by adding -lopencv_cudaarithm -lopencv_cudaimgproc to your link line. (You may have to also add -Wl,--no-as-needed before them if your GCC is configured to pass -Wl,--as-needed to the linker by default).
Employed Russian
  • 199,314
  • 34
  • 295
  • 362