Please can someone help me to link ros node with opencv correctly.
I am at my wits end trying to get a simple ROS node to link with opencv correctly. The problem is that there are two installations of opencv4 on my system.
I have a simple C++ program to read video from an esp32 chip over wifi. The program works (displays video from the esp32 cam) when I build it using this makefile:
all:
g++ -o2 -o esp32cam_to_ros_node esp32cam_to_ros_node.cpp ESP32-CAM\ Library.cpp `pkg-config opencv4 --cflags --libs` -lpthread -lcurl -std=c++11 -m64 -D _MAC_
Then I build the exact same program using CMakeLists.txt, and it no longer works (Note that the program makes no use of any ROS functionality at the moment - I stripped all of that out whilst trying to get to the root of the problem). I am simply building an executable using catkin_make under the ROS framework.
I looked at catkin_ws/build/esp32_cam_to_ros_node/link.txt and see that the opencv_core library is:
/usr/lib/x86_64-linux-gnu/libopencv_core.so.4.2.0
whereas using ldd on the working executable, from my own makefile shows:
/usr/local/lib/libopencv_core.so.4.2
So it appears the solution is to force catkin_make to use the version of opencv from /usr/local/lib
I tried to do this by adding a line to CMakeLists.txt:
set(OpenCV_DIR /usr/local/lib/cmake/opencv4/)
But now catkin_make fails saying:
CMake Warning at esp32cam_to_ros/CMakeLists.txt:141 (add_executable):
Cannot generate a safe runtime search path for target esp32cam_to_ros_node
because files in some directories may conflict with libraries in implicit
directories:
runtime library [libopencv_calib3d.so.4.2] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/usr/local/lib
runtime library [libopencv_dnn.so.4.2] in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/usr/local/lib
So now I am completely stumped ! I don't understand what cmake deems to be implicit directories. I don't know whether I should be trying to make the version of opencv in /usr/lib/x86_64-linux-gnu work, or whether there is a straightforward way of getting catkin_make to use /usr/local/lib