在制作 ROS 工作区时,没有制作目标 libopencv_calib3d.so.3.2.0 的规则,但安装了 opencv 3.4.1

No rule to make target libopencv_calib3d.so.3.2.0 but opencv 3.4.1 installed, when making ROS workspace

我在 ubuntu 上从源代码安装了 opencv 3.4.1。但是当 运行 命令 catkin_make -DCMAKE_BUILD_TYPE=Release 我得到错误:

没有创建目标“/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.3.2.0”的规则,“~/ros_ws/devel/lib/stereo_slam/image_handle_node”需要它。停止。 没有规则来创建目标 '/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.3.2.0','~/ros_ws/devel/lib/libmetrics_lib.so' 需要。停止。

我已经尝试过以下操作:openCV program compile error "libopencv_core.so.2.4: cannot open shared object file: No such file or directory" in ubuntu 12.04

[编辑] 我直接从终端使用 clion 或 catkin_make 编译时遇到同样的错误,但 clion 为发布和调试版本创建了特殊的包。我不太了解这些包,但在文件 CMakeCache.txt 中我发现了以下几行:

//Dependencies for the target
metrics_lib_LIB_DEPENDS:STATIC=general;/opt/ros/melodic/lib/libtf.so;general;/opt/ros/melodic/lib/libtf2_ros.so;general;/opt/ros/melodic/lib/libactionlib.so;general;/opt/ros/melodic/lib/libmessage_filters.so;general;/opt/ros/melodic/lib/libtf2.so;general;/opt/ros/melodic/lib/libcv_bridge.so;general;/opt/ros/melodic/lib/libimage_geometry.so;general;/usr/lib/x86_64-linux-gnu/libopencv_calib3d.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_features2d.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_flann.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_highgui.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_imgproc.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_ml.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_objdetect.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_photo.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_shape.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_stitching.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_superres.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_video.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_videoio.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_videostab.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_viz.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_aruco.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_bgsegm.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_bioinspired.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_ccalib.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_datasets.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_dpm.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_face.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_freetype.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_fuzzy.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_hdf.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_line_descriptor.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_optflow.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_phase_unwrapping.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_plot.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_reg.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_rgbd.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_saliency.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_stereo.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_structured_light.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_surface_matching.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_text.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_ximgproc.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_xobjdetect.so.3.2.0;general;/usr/lib/x86_64-linux-gnu/libopencv_xphoto.so.3.2.0;general;/opt/ros/melodic/lib/libroscpp.so;general;/usr/lib/x86_64-linux-gnu/libboost_filesystem.so;general;/usr/lib/x86_64-linux-gnu/libboost_signals.so;general;/opt/ros/melodic/lib/librosconsole.so;general;/opt/ros/melodic/lib/librosconsole_log4cxx.so;general;/opt/ros/melodic/lib/librosconsole_backend_interface.so;general;/usr/lib/x86_64-linux-gnu/liblog4cxx.so;general;/usr/lib/x86_64-linux-gnu/libboost_regex.so;general;/opt/ros/melodic/lib/libxmlrpcpp.so;general;/opt/ros/melodic/lib/libroscpp_serialization.so;general;/opt/ros/melodic/lib/librostime.so;general;/opt/ros/melodic/lib/libcpp_common.so;general;/usr/lib/x86_64-linux-gnu/libboost_system.so;general;/usr/lib/x86_64-linux-gnu/libboost_thread.so;general;/usr/lib/x86_64-linux-gnu/libboost_chrono.so;general;/usr/lib/x86_64-linux-gnu/libboost_date_time.so;general;/usr/lib/x86_64-linux-gnu/libboost_atomic.so;general;/usr/lib/x86_64-linux-gnu/libpthread.so;general;/usr/lib/x86_64-linux-gnu/libconsole_bridge.so.0.4;general;prometheus-cpp::core;general;prometheus-cpp::pull;general;ceres;general;proto;

我不明白这些 metrics_lib_LIB_DEPENDS 是什么,它们从哪里来。

问题是我通过下一个命令卸载了以前版本的 opencv:

sudo find / -name "*opencv*" -exec rm -i {} \;

通过这样做,我还删除了 ROS OpenCV 库的内容。后来甚至在重新安装 ROS 之后,这些库也没有重新安装,因为系统认为它们已安装,但其中没有任何内容。我不得不分别 apt-get 每个库。

不要清除 OpenCV...

我也错误地使用sudo find / -name "opencv" -exec rm -i {} \;删除了opencv,我遇到了同样的问题。 我用 :

解决了
sudo apt remove libopencv-dev   
sudo apt remove libopencv-core3.2

然而,并不是所有的 opencv 库都将被卸载,所以你需要删除所有随 ros 安装的 opencv 库(在我的情况下,我还需要删除 opencv-data)。您可以通过以下方式找到它们:

sudo apt list --installed | grep opencv  

之后你可以再次安装 ros melodic(或任何你正在使用的):

sudo apt install ros-melodic-desktop-full