# catkin_make not detecting .msg files in msg directory

I'm fairly new to ROS, so I don't fully comprehend what's going on. This wasn't an issue until I installed some new python libraries to my computer earlier today. Essentially, when I run catkin_make it doesn't make the msg files available as header files in the include directory in the devel directory. So when it tries to compile the .cpp files in the source directory it says "mobility/Resource.h" no such file or directory.

Now, when I move the .msg files up one directory to the same directory as mobility/ where CMakeLists.txt and package.xml are, then it does detect them. This is the current directory structure with the .msg files where they are supposed to be.

This wasn't an issue at all until today. It compiled perfectly before today.

Oh yes. So if I do rosmsg list | grep mobility all 3 msg files show up.

Doesn't compile with this:

mobility/
├── CMakeLists.txt
├── msg
│   ├── Pose2D.msg
│   ├── Resource.msg
│   └── Status.msg
├── package.xml
└── src
└── mobility.cpp

Compiles with this:

src/mobility/
├── CMakeLists.txt
├── msg
│   ├── Pose2D.msg
│   ├── Resource.msg
│   └── Status.msg
├── package.xml
├── Pose2D.msg
├── Resource.msg
├── src
│   └── mobility.cpp
└── Status.msg

Current CMake file:

cmake_minimum_required(VERSION 2.8.3)
project(mobility)

find_package(catkin REQUIRED COMPONENTS
geometry_msgs
roscpp
sensor_msgs
std_msgs
random_numbers
message_generation
)

FILES
Resource.msg
Pose2D.msg
Status.msg
)

generate_messages(
DEPENDENCIES
std_msgs
)

catkin_package(
CATKIN_DEPENDS
geometry_msgs
roscpp
sensor_msgs
std_msgs
random_numbers
message_runtime
)

mobility src/mobility.cpp
)

mobility
${catkin_LIBRARIES} ) package.xml: <?xml version="1.0"?> <package> <name>mobility</name> <version>0.2.0</version> <description>Algorithmic implementation of random search as a finite state machine</description> <maintainer email="swarmathon@cs.unm.edu">NASA Swarmathon</maintainer> <license>GPLv2</license> <buildtool_depend>catkin</buildtool_depend> <build_depend>geometry_msgs</build_depend> <build_depend>roscpp</build_depend> <build_depend>sensor_msgs</build_depend> <build_depend>std_msgs</build_depend> <build_depend>random_numbers</build_depend> <build_depend>message_generation</build_depend> <run_depend>geometry_msgs</run_depend> <run_depend>roscpp</run_depend> <run_depend>sensor_msgs</run_depend> <run_depend>std_msgs</run_depend> <run_depend>random_numbers</run_depend> <run_depend>message_runtime</run_depend> </package> first few lines of mobility.cpp: #include <ros/ros.h> //ROS libraries #include <angles/angles.h> #include <random_numbers/random_numbers.h> #include <tf/transform_datatypes.h> //ROS messages #include <std_msgs/Int16.h> #include <std_msgs/UInt8.h> #include <std_msgs/String.h> #include <sensor_msgs/Joy.h> #include <sensor_msgs/Range.h> #include <geometry_msgs/Pose2D.h> #include <geometry_msgs/Twist.h> #include <nav_msgs/Odometry.h> #include "mobility/Resource.h" #include "mobility/Pose2D.h" #include "mobility/Status.h" #include <map> // To handle shutdown signals so the node quits properly in response to "rosnode kill" #include <ros/ros.h> #include <signal.h> edit retag close merge delete ## 2 Answers Sort by » oldest newest most voted Okay so first I discovered I could run catkin_make like 4 times and then it will build all the proper header files in the include directory, but obviously that didn't solve the issue. So I searched for "catkin_make multiple times site:ros.org" and I found the solution. cmake_minimum_required(VERSION 2.8.3) project(mobility) find_package(catkin REQUIRED COMPONENTS geometry_msgs roscpp sensor_msgs std_msgs random_numbers message_generation ) add_message_files( FILES Resource.msg Pose2D.msg Status.msg ) generate_messages( DEPENDENCIES std_msgs ) catkin_package( CATKIN_DEPENDS geometry_msgs roscpp sensor_msgs std_msgs random_numbers message_runtime ) add_executable( mobility src/mobility.cpp ) add_dependencies(mobility${catkin_EXPORTED_TARGETS})

mobility
${catkin_LIBRARIES} ) I just needed to add add_dependencies(mobility${catkin_EXPORTED_TARGETS})

Where mobility is the executable(s)? for the package.

more

You definitely should have your messages in the msg folder. I would say you are missing two things:

• In catkin_package you should add EXPORTED_TARGETS mobility_generate_messages_cpp

This way, you are saying that mobility requires the messages generated and thus catkin would build them first. If you do not have these lines, it can compile if, for some reason, catkin decides to build first the messages instead of the executable. But if dependencies are not properly set then this is not guaranteed, and I would say this is what is happening to you.

more

I posted a very similar solution just now that I found, thank you for the prompt reply!

Oh yeah, why the heck don't they add this in ros.org/msg ? This would have really helped...

( 2016-02-10 02:12:44 -0500 )edit

@Manny: it is actually mentioned in the template CMakeLists.txt that gets generated by catkin_create_package for you (here).

( 2016-02-10 08:03:27 -0500 )edit

And again in the Important Prerequisites/Constraints section of wiki/catkin/CMakeLists.txt - Messages, Services, and Action Targets.

( 2016-02-10 08:05:24 -0500 )edit