ROS: learning_communication_generate_messages_cpp does not exist.错误产生原因及修复。

错误产生

在阅读《ROS机器人开发实践》这本书的3.6时,编译cmake工程出现了如下报错:

CMake Error at learning_communication/CMakeLists.txt:125 (add_dependencies):
  The dependency target "learning_communication_generate_messages_cpp" of
  target "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编译中的问题。

为什么依赖不存在呢?首先要明白这句命令的作用。看书中原话可知,这行命令是添加程序功能包动态产生的消息代码,而在本次工程中并未使用到此功能。

解决方法

以下方法任选一种即可:

  1. 降低cmake版本:即将cmake_minimum_required(VERSION 3.0.2)改为cmake_minimum_required(VERSION 2.8.3)
  2. 注释掉add_dependencies(talker ${PROJECT_NAME}_generate_messages_cpp)add_dependencies(talker ${PROJECT_NAME}_generate_messages_cpp)
  3. 通过cmake_policy修改默认行为
  • 7
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值