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
)
如果按照上面的设置,虽然可以编译成功,但是使用下面的命令,无法找到
[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