ROS: learning"/>
ROS: learning
错误产生
在阅读《ROS机器人开发实践》这本书的3.6时,编译cmake工程出现了如下报错:
CMake Error at learning_communication/CMakeLists.txt:125 (add_dependencies):The dependency target "learning_communication_generate_messages_cpp" oftarget "talker" does not exist.-- Generating done
-- Build files have been written to: /../../catkin_ws/build
Makefile:556: recipe for target 'cmake_check_build_system' failed
make: *** [cmake_check_build_system] Error 1
Invoking "make cmake_check_build_system" failed
错误产生原因
通过百度找到了如下的解决方案,即修改CMakeLists.txt
首行的版本号,将cmake版本降为2.8.3。因此确定是cmake版本问题,那么cmake的版本更新中究竟做了哪些改动呢?这个可以在cmake官方文档中查找到,描述如下:
Error on non-existent dependency in add_dependencies.
CMake 2.8.12 and lower silently ignored non-existent dependencies listed in the add_dependencies() command.
The OLD behavior for this policy is to silently ignore non-existent dependencies. The NEW behavior for this policy is to report an error if non-existent dependencies are listed in the add_dependencies() command.
This policy was introduced in CMake version 3.0. CMake version 3.0.2 warns when the policy is not set and uses OLD behavior. Use the cmake_policy command to set it to OLD or NEW explicitly.
也就是说,在2.8.12以下的版本中,cmake的add_dependencies
命令会忽略掉不存在的依赖,继续编译,而升级后的cmake遇到同样的问题采取的默认行为是报错(可通过cmake_policy
修改),因此就产生了ROS编译中的问题。
为什么依赖不存在呢?首先要明白这句命令的作用。看书中原话可知,这行命令是添加程序功能包动态产生的消息代码,而在本次工程中并未使用到此功能。
解决方法
以下方法任选一种即可:
- 降低cmake版本:即将
cmake_minimum_required(VERSION 3.0.2)
改为cmake_minimum_required(VERSION 2.8.3)
- 注释掉
add_dependencies(talker ${PROJECT_NAME}_generate_messages_cpp)
和add_dependencies(talker ${PROJECT_NAME}_generate_messages_cpp)
- 通过
cmake_policy
修改默认行为
更多推荐
ROS: learning
发布评论