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

Custom msg: strange error during building

asked 2014-07-25 16:42:40 -0500

Andromeda gravatar image

updated 2014-07-25 16:49:25 -0500

Hi, I really don t understand what is wrong in my program. I cannot get a custom msg working, I think it depends on the dependecies with the other packages. Here is my bone program: a simple publisher that should output a float32 just for testing:

#include <ros/ros.h>
#include "msg/customMsg.msg"

int main( int argc, char **argv ) {

    ros::init( argc, argv, "node_anadyr" );

    ros::NodeHandle node;

    ros::Publisher pub = node.advertise<msg::customMsg>( "topic_alpha", 100 );

    ros::Rate rate( 2 );

    while( ros::ok() ) {

        msg::customMsg message; = 3.3;
        pub.publish( message );


Of course i created a folder in my package:

jack@D-21:~/workspace_ros/src/anadyr$ ls -l | grep msg
drwxrwxr-x 2 jack jack 4096 Jul 25 23:26 msg

inside I put the following file


containing the following line:

float32 data

but when I run the catkin_make I get the following error

#### Running command: "make -j1 -l1" in "/home/wilhem/workspace_ros/build"
Scanning dependencies of target anadyr
[ 10%] Building CXX object anadyr/CMakeFiles/anadyr.dir/main.cpp.o
In file included from /home/wilhem/workspace_ros/src/anadyr/main.cpp:2:0:
/home/wilhem/workspace_ros/src/anadyr/msg/customMsg.msg:1:1: error: ‘float32’ does not name a type
 float32 data
make[2]: *** [anadyr/CMakeFiles/anadyr.dir/main.cpp.o] Fehler 1
make[1]: *** [anadyr/CMakeFiles/anadyr.dir/all] Fehler 2
make: *** [all] Fehler 2
Invoking "make" failed

Here is my CMakelist.txt

cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS roscpp message_generation std_msgs)

## Generate messages in the 'msg' folder

## Generate added messages and services with any dependencies listed here


# add_executable(anadyr_node src/anadyr_node.cpp)
add_executable(anadyr main.cpp)
target_link_libraries(anadyr ${catkin_LIBRARIES})

and here my package.xml:

<?xml version="1.0"?>
  <description>The anadyr package</description>
  <maintainer email="">wilhem</maintainer>




I read all the tutorials I could find, but it didnt work. What worng in my dependencies?!? What should I do to use custom messages in my application? Regards

edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted

answered 2014-07-25 17:19:58 -0500

ahendrix gravatar image

updated 2014-07-25 17:50:09 -0500

Instead of including the message file msg/customMsg.msg, you should be including the generated C++ header: anadyr/customMsg.h

You may also need to add add_dependencies(anadyr ${catkin_EXPORTED_TARGETS}) to your CMakeLists.txt to make sure that the message generation is run before your program is compiled.

edit flag offensive delete link more


Thanx but it doesn t find the generated file /home/jack/workspace_ros/src/anadyr/main.cpp:2:27: fatal error: anadyr/customMsg.h: file or folder not found #include "anadyr/customMsg.h" ^ compilation terminated. make[2]: *** [anadyr/CMakeFiles/anadyr.dir/main.cpp.o] Fehler 1 make[1]: *** [anadyr/CMakeFiles/anadyr.dir/all] Fehler 2 make: *** [all] Fehler 2 Invoking "make" failed What s wrong`?

Andromeda gravatar image Andromeda  ( 2014-07-25 17:27:04 -0500 )edit

could you tell me, what should I change if I want to put all *.msg files in a third directory and not in the same folder of the package?

Andromeda gravatar image Andromeda  ( 2014-07-26 00:39:52 -0500 )edit

answered 2014-07-26 00:38:13 -0500

Andromeda gravatar image

updated 2014-07-26 00:43:40 -0500

Ok it didn t work anyway BUT thanks to your Idea I put and changed ONLY this line of code in my CMakeLists.txt


and now it is compiling, building and working even for the subscriber.

I m a little bit frustrated because I read through all 4 Websites regarding the custom msg and not a tutorial is mentionign to put that line of code in that file. BUT...people are encouraged to read the tutorials at first.... It would had save me at least 3 hours of trying....

Anyway awesome!!! Thank you very much!

edit flag offensive delete link more



This is clearly documented in the C++ publisher and subscriber tutorial:

ahendrix gravatar image ahendrix  ( 2014-07-26 02:31:32 -0500 )edit

Question Tools

1 follower


Asked: 2014-07-25 16:42:40 -0500

Seen: 7,071 times

Last updated: Jul 26 '14