在Ubuntu中编译一个基于OpenCV和ROS的项目

在我的项目中运行CMake(实际上是rosmake)时,我收到一个错误。 我已经安装OpenCV,但我得到以下错误:

Linking CXX shared library ../lib/libCornerHelper.so /usr/bin/ld: cannot find -lopencv_contrib /usr/bin/ld: cannot find -lopencv_legacy /usr/bin/ld: cannot find -lopencv_stitching /usr/bin/ld: cannot find -lopencv_gpu /usr/bin/ld: cannot find -lopencv_objdetect /usr/bin/ld: cannot find -lopencv_calib3d /usr/bin/ld: cannot find -lopencv_features2d /usr/bin/ld: cannot find -lopencv_video /usr/bin/ld: cannot find -lopencv_highgui /usr/bin/ld: cannot find -lopencv_ml /usr/bin/ld: cannot find -lopencv_imgproc /usr/bin/ld: cannot find -lopencv_flann /usr/bin/ld: cannot find -lopencv_core collect2: ld returned 1 exit status make[3]: *** [../lib/libCornerHelper.so] Error 1 

有谁知道如何解决这个问题?

显然,他找不到opencv来链接你的项目。 你把它安装在/ usr或/ usr / local以外的其他地方吗?

如果是这样,则需要将路径添加到LD_LIBRARY_PATH变量等。 当你运行这个系统时,你的系统是什么意思?

 pkg-config --cflags --libs opencv 

如果你有这样的事情,那么你的系统是好的。

 -I/opt/opencv/include/opencv -I/opt/opencv/include -L/opt/opencv/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann 

但如果你不这样做,你的系统无法找到它,cmake也不会找到它:

 Package opencv was not found in the pkg-config search path. Perhaps you should add the directory containing `opencv.pc' to the PKG_CONFIG_PATH environment variable No package 'opencv' found 

如果你在ROS中使用OpenCV,如果你已经在你的manifest.xml文件中声明了对opencv2的依赖,那么应该自动选择合适的链接标志和路径。

如果你仍然有问题,我建议你搜索ROS答案 ,如果你没有找到任何东西,那么问你的问题。 这是官方的ROS支持论坛,可能会让你更好地回答ROS特定的问题,而不是StackOverflow。