ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

CMake Error - WritingPublisherSubscriber(c++)

asked 2017-08-30 09:13:11 -0500

hyuu gravatar image

Hello everyone,

I'm new to ROS and browsing ROS tutorials I'm stuck with the problem in Writing a Simple Publisher and Subs.. tutorial.

Basically I followed it till the end and finally when I want to execute the catkin_make in catkin_ws $ I get an error message

CMake Error at /opt/ros/kinetic/share/genmsg/cmake/genmsg-extras.cmake:94 (message):
  add_message_files() directory not found:
  /home/hyuu/catkin_ws/src/beginner_tutorials/msg
Call Stack (most recent call first):
  beginner_tutorials/CMakeLists.txt:8 (add_message_files)

This is how my CMakeLists.txt inside beginner_tutorials folder looks like(copy-paste from tutorials):

cmake_minimum_required(VERSION 2.8.3)
project(beginner_tutorials)

## Find catkin and any catkin packages
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs genmsg)

## Declare ROS messages and services
add_message_files(DIRECTORY msg FILES Num.msg)
add_service_files(DIRECTORY srv FILES AddTwoInts.srv)

## Generate added messages and services
generate_messages(DEPENDENCIES std_msgs)

## Declare a catkin package
catkin_package()

include_directories(include ${catkin_INCLUDE_DIRS})

add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker beginner_tutorials_generate_messages_cpp)

add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_tutorials_generate_messages_cpp)

Thanks for any help provided!

edit retag flag offensive close merge delete

Comments

Do you actually have a /home/hyuu/catkin_ws/src/beginner_tutorials/msg directory? Is your Num.msg file in that directory? If yes to both, what are the permissions on the directory and file?

jarvisschultz gravatar image jarvisschultz  ( 2017-08-30 09:59:22 -0500 )edit

Actually I did everything as described in tutorial and I do not have that folder or any file. I browsed a lot of different answers but none of them helped me. Did I miss some steps? I assumed it's made automatically or sth.

hyuu gravatar image hyuu  ( 2017-08-30 11:00:14 -0500 )edit

The Creating a ROS msg and srv tutorial that @jayess linked to in his answer has a section where you specifically create the message and service files in the msg/ and srv/ directories.

jarvisschultz gravatar image jarvisschultz  ( 2017-08-31 12:21:15 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-08-30 13:39:49 -0500

jayess gravatar image

updated 2017-08-30 14:25:26 -0500

Did you copy and paste it? In the tutorial, the CMakeLists.txt has the following lines

add_message_files(FILES Num.msg)
add_service_files(FILES AddTwoInts.srv)

but you have

add_message_files(DIRECTORY msg FILES Num.msg)
add_service_files(DIRECTORY srv FILES AddTwoInts.srv)

Notice the difference? Yours says DIRECTORY msg and DIRECTORY srv while the tutorial only says FILES.

Also, the Writing a Simple Publisher and Subscriber (C++) presumes that you completed the Creating a ROS msg and srv tutorial where the msg and srv folders and definitions for the custom message and service are created.

edit flag offensive delete link more

Comments

Thanks! I copied the part from the code above, not the final part. Still didn't solve my problem but probably that I missed this Creating ROS msg and srv tutorial made this problem :/

hyuu gravatar image hyuu  ( 2017-08-30 15:12:52 -0500 )edit

While the CMakeLists.txt file linked in this answer is different than the OP's file (and fixes the error), it's worth pointing out that file in the WritingPublisherSubscriber(c++) tutorial is the same as the OP's file

jarvisschultz gravatar image jarvisschultz  ( 2017-08-31 12:15:27 -0500 )edit

This version works correctly as long as you follow the instructions in the CreatingMsgAndSrv tutorial (which is the previous tutorial) which has you create Num.msg in the msg/ directory of your package.

jarvisschultz gravatar image jarvisschultz  ( 2017-08-31 12:18:30 -0500 )edit

@jarvisschultz: Thanks for pointing out that the one that the OP posted is in the tutorial. There are actually two CMakeLists.txt which doesn't help clear the confusion. The one that I used is underneath the one that @hyuu used. I scrolled from the bottom up so I didn't see the first one.

jayess gravatar image jayess  ( 2017-08-31 12:23:33 -0500 )edit

But, the tutorial says that the final one should be the one that I linked to.

jayess gravatar image jayess  ( 2017-08-31 12:24:04 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2017-08-30 09:13:11 -0500

Seen: 819 times

Last updated: Aug 30 '17