warning: ../../lib/libopencv_core.so, needed by ./lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)

asked 2019-03-28 20:32:10 -0500

ice_and_ice gravatar image

updated 2019-03-28 21:47:26 -0500

I have built the opencv project with cmake without errors. But when I compiled my project, I got warnings like this:

warning: ../../lib/libopencv_core.so, needed by ./lib/libopencv_highgui.so, not found (try using -rpath or -rpath-link)

I copyed the opencv library to the current folder and configed the environment. Then I run it and got the following error:

error while loading shared libraries: ../../lib/libopencv_videoio.so

I found it is because the compiler options in these files called link.txt. They are in their own folder like build/modules//CMakeFiles/opencv_.dir. For example, the link.txt of highgui is in build/modules/highgui/CMakeFiles/opencv_highgui.dir/. And the build folder is built by cmake-gui. These files is writed like this:

g++ -fPIC -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -fomit-frame-pointer -ffunction-sections -fdata-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-deprecated-declarations -O3 -DNDEBUG -DNDEBUG -lpthread -ldl -lm -lrt -Wl,-rpath-link=./lib -Wl,-rpath=./lib -shared -o ../../lib/libopencv_highgui.so CMakeFiles/opencv_highgui.dir/src/window.cpp.obj CMakeFiles/opencv_highgui.dir/src/roiSelector.cpp.obj ../../lib/libopencv_videoio.so ../../lib/libopencv_imgcodecs.so ../../lib/libopencv_imgproc.so ../../lib/libopencv_core.so

Because the file libopencv_core.so is depended by libopencv_highgui.so, I have to copy these *.so to the ../../lib folder relative to current folder. Then it runs.

How to solve the problem when building opencv?

edit retag flag offensive close merge delete

Comments

os ? opencv version ? compiler ?

berak gravatar imageberak ( 2019-03-31 06:13:26 -0500 )edit