当前位置: 首页 > 工具软件 > robotarm-add > 使用案例 >

add_message_files() directory not found:

澹台正业
2023-12-01

ROS在添加msg文件时发生找不到目录的错误

CMake Error at /opt/ros/melodic/share/genmsg/cmake/genmsg-extras.cmake:94 (message):
  add_message_files() directory not found:
  /home/vector/Robot/catkin_ws/src/learning_communication/msg
Call Stack (most recent call first):
  learning_communication/CMakeLists.txt:51 (add_message_files)

CMakeLists.txt中的文件的写法:

## Generate messages in the 'msg' folder
add_message_files(
  FILES
  Person.msg    # 自定义的消息文件
  # Message1.msg
  # Message2.msg
)

猜测:add_message_files是默认在package_name/src目录下寻找.msg文件的,会发生找不到的情况,但是我的.msg文件是放在package_name/src/msg目录下的,所以需要指出目录,将上面的修改为:

## Generate messages in the 'msg' folder
add_message_files(
  DIRECTORY src/msg      # 文件的目录, 默认在src下面,需要指明地址
  FILES
  Person.msg
  # Message1.msg
  # Message2.msg
)

Could not find msg ‘Person’

如果按照上面的设置,虽然可以编译成功,但是使用下面的命令,无法找到

[xxx@xxx:~/Robot/catkin_ws → master]$ rosmsg show Person
Could not find msg 'Person'

经过痛苦的研究发现,.msg文件一般放在package_name/msg/目录下,移动之后,修改CMakeLists.txt如下即可:

## Generate messages in the 'msg' folder
add_message_files(
  DIRECTORY msg      # 文件的目录, 默认在src下面,需要指明地址
  FILES
  Person.msg
  # Message1.msg
  # Message2.msg
)

再次查看的结果:

[xxx@xxx:~/Robot/catkin_ws → master]$ rosmsg show Person
[learning_communication/Person]:
uint8 unknown=0
uint8 male=1
uint8 female=2
string name
uint8 sex
uint8 age
 类似资料:

相关阅读

相关文章

相关问答