ROS: learning

编程入门 行业动态 更新时间:2024-10-10 09:20:25

<a href=https://www.elefans.com/category/jswz/34/1768665.html style=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编译中的问题。

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

解决方法

以下方法任选一种即可:

  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修改默认行为

更多推荐

ROS: learning

本文发布于:2024-03-05 11:06:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1712118.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ROS   learning

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!