PDA

View Full Version : How to resolve library (.so) dependancy ?



npatil15
6th March 2019, 07:53
Hi,

I'm using opencv3.3.1 for Linux platform. having tree structure like this below
.
|---- bin
|---- build
| |---- include
|----include
| |---- opencv
| |---- opencv2
|---- lib
| |---- pkgconfig
| |---- python2.7
|---- share
|---- OpenCV

I have linked all the libraries which is on the path: /lib


libopencv_calib3d.so libopencv_imgcodecs.so.4.0.0 libopencv_stitching.so.4.0
libopencv_calib3d.so.4.0 libopencv_imgproc.so libopencv_stitching.so.4.0.0
libopencv_calib3d.so.4.0.0 libopencv_imgproc.so.4.0 libopencv_superres.so
libopencv_core.so libopencv_imgproc.so.4.0.0 libopencv_superres.so.4.0
libopencv_core.so.4.0 libopencv_ml.so libopencv_superres.so.4.0.0
libopencv_core.so.4.0.0 libopencv_ml.so.4.0 libopencv_videoio.so
libopencv_features2d.so libopencv_ml.so.4.0.0 libopencv_videoio.so.4.0
libopencv_features2d.so.4.0 libopencv_objdetect.so libopencv_videoio.so.4.0.0
libopencv_features2d.so.4.0.0 libopencv_objdetect.so.4.0 libopencv_video.so
libopencv_flann.so libopencv_objdetect.so.4.0.0 libopencv_video.so.4.0
libopencv_flann.so.4.0 libopencv_photo.so libopencv_video.so.4.0.0
libopencv_flann.so.4.0.0 libopencv_photo.so.4.0 libopencv_videostab.so
libopencv_highgui.so libopencv_photo.so.4.0.0 libopencv_videostab.so.4.0
libopencv_highgui.so.4.0 libopencv_shape.so libopencv_videostab.so.4.0.0
libopencv_highgui.so.4.0.0 libopencv_shape.so.4.0 pkgconfig
libopencv_imgcodecs.so libopencv_shape.so.4.0.0 python2.7
libopencv_imgcodecs.so.4.0 libopencv_stitching.so


For linking I have tried with this below,

unix|win32: LIBS += -L$${PATHOFDIR}/video -lvideo
INCLUDEPATH += $${PATHOFDIR}/video
DEPENDPATH += $${PATHOFDIR}/video

OPENCVLINUXDIR = /home/thirdparty/opencv/opencv_3.3.1

INCLUDEPATH += $${OPENCVLINUXDIR}/include
DEPENDPATH += $${OPENCVLINUXDIR}/include

LIBS += -L$${OPENCVLINUXDIR}/lib -lopencv_core -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_highgui -lopencv_imgcodecs -lopencv_imgproc -lopencv_ml -lopencv_objdetect -lopencv_photo -lopencv_shape -lopencv_stitching -lopencv_superres -lopencv_video -lopencv_videoio -lopencv_videostab

dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_core.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_core.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_calib3d.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_calib3d.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_features2d.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_features2d.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_flann.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_flann.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_highgui.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_highgui.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_imgcodecs.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_imgcodecs.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_imgproc.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_imgproc.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_ml.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_ml.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_objdetect.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_objdetect.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_photo.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_photo.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_shape.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_shape.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_stitching.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_stitching.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_superres.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_superres.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_video.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_video.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_videoio.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_videoio.so.4.0.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_videostab.so.4.0
dependencies.files += $${OPENCVLINUXDIR}/lib/libopencv_videostab.so.4.0.0

Please help me out why I'm getting this errors

Still 2 libraries I'm unable to link, say (libopencv_core.so.4.0, libopencv_videoio.so.4.0), got this below error,

:-1: warning: libopencv_core.so.4.0, needed by /home/test/UnitTest/../../build/release/modules/video/libvideo.so, not found (try using -rpath or -rpath-link)
:-1: warning: libopencv_videoio.so.4.0, needed by /home/test/UnitTest/../../build/release/modules/video/libvideo.so, not found (try using -rpath or -rpath-link)

And additionally getting this below error also,

/home/thirdparty/opencv/opencv_3.3.1/include/opencv2/core/mat.inl.hpp:511: error: undefined reference to `cv::Mat::updateContinuityFlag()'

d_stranz
6th March 2019, 22:37
The linux linker is stupid. It only pulls the dependencies it knows about from the libraries as it encounters them in the dependency list.

So if you have a library that depends on another library, you must list the libraries in the order of their dependency. If libopencv_video depends on libopencv_core, then libopencv_video must be in the dependency list before libopencv_core. Likewise, if libopencv_videoio depends on libopencv_video, it must be in the list before libopencv_video. The linker will then build up a set of dependencies so that by the time it gets to libopencv_core, it can pull in the items from libopencv_core that satisfy all of the dependencies from all of the previous code.

So in your LIBS command, -lopencv_core should be last, and -lopencv_videoio should come before -lopencv_video.

By the way, I do not think you should list the full version numbers for the libraries. When a library gets installed, it usually creates symlinks from libXYZ.so to libXYZ.so.4, libXYZ.so.4.0, and libXYZ.so.4.0.0 so that when you link to simply libXYZ.so, the symlinks will pull in the most recent version of the library.

In your case, the order in which you have added the libraries is probably backwards, and because you list the same library twice, it means the linker is wasting time processing each library twice (because libXYZ.so.4.0 is symlinked to libXYZ.so.4.0.0 so they are really the same library).

npatil15
7th March 2019, 06:29
Hi d_stranz,

The information you provide is surly added knowledge to me.
Where as I have tried as you said and multiple ways but still the same error.

Here is the scenario:
I have one module developed in QT, say Video module, in which I have uses same libraries and in the same order, their it works pretty well (No Errors or warnings).
Now I'm doing UnitTest for Video module, and calling method of Video module for test, and done the same configuration in UnitTest as done in Video module (Getting warnings and errors as already explained)

The warnings I'm getting it seems to be some issue in because of Video Module. Because as I change the order in Video.pro as 1st -lopencv_core and 2nd -lopencv_videoio, then in my UnitTest I got warning first for opencv_core and then videoio. And if I change the order then got the warnings first videoio and then opencv_core.

So from the observation it looks like the order in UnitTest not affecting it. actually the order in Video module affecting my UnitTest to generate error.

Hope I'm able to explain the issue

Thanks

d_stranz
7th March 2019, 17:11
Maybe you should ask about this on the OpenCV forum. It sounds like there is a circular dependency between the two libraries. I cannot believe that this would be true for such a popular framework as OpenCV, so maybe your problem has something to do with a function of the same name in two different namespaces.