背景:
在ROS(Robot Operating System)中,catkin
是用于构建ROS包的构建系统
想使用CLion开发PCL,在ROS 中做仿真。CmakeLists.txt 报错:
find_package(catkin REQUIRED)
CMake Error at CMakeLists.txt:14 (find_package):
By not providing "Findcatkin.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "catkin", but
CMake did not find one.
Could not find a package configuration file provided by "catkin" with any
of the following names:
catkinConfig.cmake
catkin-config.cmake
Add the installation prefix of "catkin" to CMAKE_PREFIX_PATH or set
"catkin_DIR" to a directory containing one of the above files. If "catkin"
provides a separate development package or SDK, be sure it has been
installed.
1. 检查catkin是否已经安装
安装catkin:
sudo apt-get install ros-noetic-catkin
查看版本号:
catkin --version
博主已经安装了,不是没有安装的问题
2.设置catkin 路径
在CmakelLists.txt 中添加(放在find前面)
set(catkin_DIR opt/ros/noetic)
或者在 .bashrc中添加环境变量,效果一样,不赘述。
但令人发疯的是,两种办法都没有用,还是报错
3.(原因)需要设置Module模式下的路径!
仔细看报错的第一段话,需要设置CATKIN_MODULE_PATH
这里引用其他博主的博客
摘抄如下:
命令find_package有两种模式:Module模式和Config模式.
(表面上都是find_package(xxxx REQUIRED))
Module模式会检索Findxxx.cmake
CMakeLists.txt
cmake/FindFoo.cmake
cmake/FindBoo.cmake
Config模式会检索xxxConfig.cmake
CMakeLists.txt
cmake/FooConfig.cmake
注意了,Module的搜索优先级高于Config的,网上一堆Config模式的操作
但是初学者很有可能是Module模式来检索的,那怎么找的到呢对吧
Module模式底下的路径很可能还是空的
所以当你需要使用一个第三方库的时候(确保这个库是安装好的)
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_39790009/article/details/123358472
=======================================================================
最后,设置如下:
set(CMAKE_PREFIX_PATH "/opt/ros/<ROS版本>")
set(CMAKE_MODULE_PATH "${CMAKE_PREFIX_PATH}/share/catkin/cmake")
报错解决!
码字不易,留个赞再走~