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

Getting a compile error including rosgraph_msgs/Log

asked 2021-03-17 13:24:04 -0500

Rhapsodus gravatar image

updated 2021-03-17 13:41:10 -0500

Greetings,

I am trying to use rosgraph_msgs/Log to subscribe to rosout and when I include the header file I get the following compile error:

<command-line>:0:7: error: expected identifier before numeric constant
/opt/ros/melodic/include/rosgraph_msgs/Log.h:95:5: note: in expansion of macro ‘DEBUG’
     DEBUG = 1,
     ^~~~~
<command-line>:0:7: error: expected ‘}’ before numeric constant
/opt/ros/melodic/include/rosgraph_msgs/Log.h:95:5: note: in expansion of macro ‘DEBUG’
     DEBUG = 1,
     ^~~~~
<command-line>:0:7: error: expected unqualified-id before numeric constant
/opt/ros/melodic/include/rosgraph_msgs/Log.h:95:5: note: in expansion of macro ‘DEBUG’
     DEBUG = 1,
     ^~~~~

In file included from ....
/opt/ros/melodic/include/rosgraph_msgs/Log.h:103:52: error: ‘ContainerAllocator’ was not declared in this scope
   typedef boost::shared_ptr< ::rosgraph_msgs::Log_<ContainerAllocator> > Ptr;
                                                    ^~~~~~~~~~~~~~~~~~
/opt/ros/melodic/include/rosgraph_msgs/Log.h:103:70: error: template argument 1 is invalid
   typedef boost::shared_ptr< ::rosgraph_msgs::Log_<ContainerAllocator> > Ptr;
                                                                      ^
/opt/ros/melodic/include/rosgraph_msgs/Log.h:103:72: error: template argument 1 is invalid
   typedef boost::shared_ptr< ::rosgraph_msgs::Log_<ContainerAllocator> > Ptr;
                                                                        ^
/opt/ros/melodic/include/rosgraph_msgs/Log.h:104:52: error: ‘ContainerAllocator’ was not declared in this scope
   typedef boost::shared_ptr< ::rosgraph_msgs::Log_<ContainerAllocator> const> ConstPtr;
                                                    ^~~~~~~~~~~~~~~~~~
/opt/ros/melodic/include/rosgraph_msgs/Log.h:104:70: error: template argument 1 is invalid
   typedef boost::shared_ptr< ::rosgraph_msgs::Log_<ContainerAllocator> const> ConstPtr;
                                                                      ^
/opt/ros/melodic/include/rosgraph_msgs/Log.h:104:77: error: template argument 1 is invalid
   typedef boost::shared_ptr< ::rosgraph_msgs::Log_<ContainerAllocator> const> ConstPtr;
                                                                             ^
/opt/ros/melodic/include/rosgraph_msgs/Log.h:110:45: error: ‘Log’ is not a member of ‘rosgraph_msgs’
 typedef boost::shared_ptr< ::rosgraph_msgs::Log > LogPtr;
                                             ^~~
/opt/ros/melodic/include/rosgraph_msgs/Log.h:110:45: note: suggested alternative: ‘Log_’
 typedef boost::shared_ptr< ::rosgraph_msgs::Log > LogPtr;
                                             ^~~
                                             Log_
/opt/ros/melodic/include/rosgraph_msgs/Log.h:110:45: error: ‘Log’ is not a member of ‘rosgraph_msgs’
/opt/ros/melodic/include/rosgraph_msgs/Log.h:110:45: note: suggested alternative: ‘Log_’
 typedef boost::shared_ptr< ::rosgraph_msgs::Log > LogPtr;
                                             ^~~
                                             Log_
/opt/ros/melodic/include/rosgraph_msgs/Log.h:110:49: error: template argument 1 is invalid
 typedef boost::shared_ptr< ::rosgraph_msgs::Log > LogPtr;
                                                 ^
/opt/ros/melodic/include/rosgraph_msgs/Log.h:111:45: error: ‘Log’ is not a member of ‘rosgraph_msgs’
 typedef boost::shared_ptr< ::rosgraph_msgs::Log const> LogConstPtr;
                                             ^~~
/opt/ros/melodic/include/rosgraph_msgs/Log.h:111:45: note: suggested alternative: ‘Log_’
 typedef boost::shared_ptr< ::rosgraph_msgs::Log const> LogConstPtr;
                                             ^~~
                                             Log_
/opt/ros/melodic/include/rosgraph_msgs/Log.h:111:45: error: ‘Log’ is not a member of ‘rosgraph_msgs’
/opt/ros/melodic/include/rosgraph_msgs/Log.h:111:45: note: suggested alternative: ‘Log_’
 typedef boost::shared_ptr< ::rosgraph_msgs::Log const> LogConstPtr;
                                             ^~~
                                             Log_
/opt/ros/melodic/include/rosgraph_msgs/Log.h:111:54: error: template argument 1 is invalid
 typedef boost::shared_ptr< ::rosgraph_msgs::Log const> LogConstPtr;
                                                      ^
/opt/ros/melodic/include/rosgraph_msgs/Log.h:155:1: error: expected declaration before ‘}’ token
 } // namespace rosgraph_msgs
 ^

When I comment out #include <rosgraph_msgs log.h=""> I compile fine. rosgraph_msgs is added to my catkin_package in cmake and in my package.xml. Versions: 1.11.2-0bionic.20201017.050047

Is ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2021-03-17 16:06:02 -0500

gvdhoorn gravatar image

updated 2021-03-17 16:09:16 -0500

You provide very little information (not even the platform / OS you're building this on), so this is just a guess.

The error you show has this:

/opt/ros/melodic/include/rosgraph_msgs/Log.h:95:5: note: in expansion of macro ‘DEBUG’
     DEBUG = 1,

DEBUG is not a macro in /opt/ros/melodic/include/rosgraph_msgs/Log.h, but a member of an enum.

From /opt/ros/melodic/include/rosgraph_msgs/Log.h:

  enum {
    DEBUG = 1,
    INFO = 2,
    WARN = 4,
    ERROR = 8,
    FATAL = 16,
  };

Would you perhaps happen to have #defined a DEBUG macro yourself? Or have you used #define DEBUG <some_value> yourself?

That could cause this problem as the symbols would clash.

The rest of the errors are not interesting at this point, as it's very likely they're caused by the compiler trying to make sense of the rest of the file, which it can't.

Is there a hidden header dependency?

if that was the case, in code which is around 12 years old, we would have probably seen more reports about this.

edit flag offensive delete link more

Comments

First off, I appreciate the help and sorry for not posting the Melodic / Ubuntu version. You are spot on correct here. There was a less than obvious Debug flag being set in the CmakeLists file. Removing these allowed the conflict to resolve.

set(CMAKE_C_FLAGS_DEBUG "-g -DDEBUG")
set(CMAKE_CXX_FLAGS_DEBUG "-g -DDEBUG")
Rhapsodus gravatar image Rhapsodus  ( 2021-03-17 18:49:01 -0500 )edit

Hm. I would not have expected those defines to cause a problem. We compile many parts of ROS with Debug settings enabled, and I've not run into a conflict there.

Are you sure it was those?

gvdhoorn gravatar image gvdhoorn  ( 2021-03-18 03:11:20 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2021-03-17 13:24:04 -0500

Seen: 194 times

Last updated: Mar 17 '21