如何从 ros 节点的 saperate 目录中导入外部 .cpp 和 .h 文件? [英] How to import an external .cpp and .h files from a saperate directory in a ros node?

查看:38
本文介绍了如何从 ros 节点的 saperate 目录中导入外部 .cpp 和 .h 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 catkin 包中有一个简单的 ros 节点.现在我想在我的节点中包含一个 .h 和另一个 .cpp 文件..h 和 .cpp 文件是另一个目录的一部分,该目录不是具有此节点的 catkin 包的一部分.所以我相信我需要在我的包的 cmake 列表中添加外部目录,但我不确定如何.谁能帮我怎么办?我还应该链接 .h 文件的目标吗?

I have a simple ros node inside a catkin package. Now i want to include a .h along with another .cpp file in my node. The .h and .cpp files are part of another directory which is not part of the catkin package that has this nodes. So I believe I need to add the external directory in my package's cmake lists but I am not sure how. Can anyone help me how ? Should I also link targets of the .h files ?

推荐答案

catkin 只是 CMake 的扩展,因此您可以使用标准的 CMake 命令来解决您的问题.

catkin is just an extension of CMake, so you can use the standard CMake commands to solve your problem.

首先,您需要添加包含目录(doc) 喜欢:

First, you need to add the include directory (doc) like:

include_directories(${YOUR_DIRECTORY})

定义源文件可以通过设置一个变量来完成(doc)

Defining the source files can be done by setting a variable (doc)

set(EXT_SOURCES
  ${YOUR_DIRECTORY}/file.cpp
)

在您的节点库中使用这些源文件(doc)和/或节点(doc)可执行文件:

using these source files at your node libaray (doc) and / or node (doc) executable:

add_library(library_name ${EXT_SOURCES})
add_executable(node_executable_name ${EXT_SOURCES})

这篇关于如何从 ros 节点的 saperate 目录中导入外部 .cpp 和 .h 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆