Ask Your Question
0

Compiling tf or tf2 with -std=gnu++0x

asked 2011-11-19 20:48:27 -0600

sergey_alexandrov gravatar image

Hello,

I am trying to rosmake a package (modular_cloud_matcher) which forces -std=gnu++0x compiler option. This results in the following error:

/opt/ros/electric/stacks/geometry/tf/include/tf/tf.h:91:44: error: ‘constexpr’ needed for in-class initialization of static data member ‘DEFAULT_CACHE_TIME’ of non-integral type

and a similar one in tf2.

A possible solution is to change in tf.h from

static const double DEFAULT_CACHE_TIME = 10.0;

to

static constexpr double DEFAULT_CACHE_TIME = 10.0;

I suppose, however, this is not the right way to solve the issue, because next update will remove my modification. I am rather new to the ROS community, so I would like to know what should be done in such cases.

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
2

answered 2011-11-20 02:13:05 -0600

joq gravatar image

When you find a compiler problem like this, please open a defect ticket for the appropriate ROS component (in this case geometry). Mention the exact system version and compiler (i.e. gcc --version) you use.

In this case, constexpr is a new feature of the recent C++11 standard, which is not supported for any current ROS distribution. As REP-0003 states:

  • "Use of C++[0|1]x or tr1 features are only allowed if support for that feature is checked at compile time, and equivalent functionality exists without requiring C++[0|1]x code. A wholesale jump to C++[0|1]x will not happen until all commonly used OS platforms fully support it."

So, while you should submit your patch with the defect ticket, the full solution will need to be somewhat different, to support all the other ROS platforms.

edit flag offensive delete link more

Comments

Thanks for the suggestion. I opened a ticket at ros-pkg trac. Clearly, 'constexpr' is not an acceptable solution as it won't compile with C++03.
sergey_alexandrov gravatar imagesergey_alexandrov ( 2011-11-20 08:12:58 -0600 )edit
0

answered 2012-05-08 09:14:02 -0600

npsimons gravatar image

Technically, the old C++ standard says that non-integer constant data is illegal in class declarations. The easy way to fix this is to define it in the source file. I fixed it by moving the definition of DEFAULT_CACHE_TIME to tf.cpp and it now works with GCC 4.4.5 on Debian 6.0.4, no --std argument needed. I'm pretty sure it will also work in C++0x. constexpr is more for template metaprogramming and places where you can't separate the definition from the declaration, or would like to make something constant for performance tuning.

edit flag offensive delete link more
0

answered 2012-03-18 00:34:24 -0600

updated 2012-03-18 00:59:19 -0600

Hello,

I am the maintainer of modular_cloud_matcher, and while I'm aware of ROS' repulsion of the use of C++0x, I decided to use it nevertheless because it made the code much cleaner and worked for the main ROS platforms starting from GCC 4.4 (Ubuntu Lucid). I did not use any features not explicitly supported and tested with GCC 4.4. Moreover, I think that it is good people begin testing ROS with C++0x as it will help with the eventual transition.

I did not expect too much problems such as this one to happen, as C++0x is supposed to be highly backward compatible, but it does happen sometimes.

I have created patches that fix these issues, see the related ticket

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2011-11-19 20:48:27 -0600

Seen: 1,018 times

Last updated: May 08 '12