我们有多个节点使用message_generation
生成.h
消息文件供其他节点使用。将生成的消息包含在非生成包的CMakeLists
和package.xml
中的正确方法是什么?
当前,我正在执行以下操作,但是我总是第一次无法构建,然后必须重新构建,第二次才能运行。就像它没有意识到它必须先生成消息一样。可能是在package_containing_generated_messages
软件包中设置了错误吗?
CMakeLists.txt:
find_package(catkin REQUIRED
roscpp
package_containing_generated_messages
)
catkin_package(CATKIN_DEPENDS
roscpp
package_containing_generated_messages #I don't think this one is needed, is it?
)
package.xml:
<build_depend>package_containing_generated_messages</build_depend>
<exec_depend>package_containing_generated_messages</exec_depend>
答案 0 :(得分:0)
几乎正确,但是您缺少一个关键的依赖项。 这是一个基于您的代码片段的示例,该代码片段使用您自己的消息构建了节点foo(但请不要忘记package.xml中的依赖关系也很重要,但是无论如何您都可以纠正它们)。
cmake_minimum_required(VERSION 2.8.3)
project(foo_package)
find_package(catkin REQUIRED
roscpp
package_containing_generated_messages
)
catkin_package(CATKIN_DEPENDS
roscpp
package_containing_generated_messages
)
include_directories(include
${catkin_INCLUDE_DIRS}
)
## Declare a cpp executable
add_executable(foo foo.cpp)
## Add cmake target dependencies of the executable/library
## as an example, message headers may need to be generated before nodes
add_dependencies(foo package_containing_generated_messages_generate_messages_cpp)
## Specify libraries to link a library or executable target against
target_link_libraries(foo
${catkin_LIBRARIES}
)
重要的一行是这一行add_dependencies(foo package_containing_generated_messages_generate_messages_cpp)
,它在尝试构建package_containing_generated_messages_generate_messages_cpp
之前确保标志foo
存在。因此,可以确保在生成二进制文件之前先生成消息头。请注意,ROS为您的软件包名称添加了后缀,例如<my_msgs_package_name>_generate_messages_cpp
。 Here is some reference。