rosidl icon indicating copy to clipboard operation
rosidl copied to clipboard

Consider narrowing the scope of `#undef ERROR` in generated message code

Open gerkey opened this issue 8 years ago • 5 comments

https://github.com/ros2/rosidl/commit/d4264b70387e91b8f46a40ff307881f28ff07c04#commitcomment-17146232

gerkey avatar Apr 18 '16 17:04 gerkey

This is a known problem that we face is ROS1 as well (e.g. https://github.com/ros/geometry2/issues/172) and it would be great to see how we can address these collisions with Windows defined in the near future

mikaelarguedas avatar Aug 07 '17 18:08 mikaelarguedas

This issue has come up again here:

The generated file build\tf2_msgs\rosidl_generator_cpp\tf2_msgs\msg\tf2_error__struct.hpp contains the following code that conflicts with Windows' definition:

  // constants
  enum { NO_ERROR = 0u };

Windows SDK defines macro NO_ERROR in Error.h:

#define NO_ERROR            0

We have confirmed for myself that that culprit is Windows SDK. On a clean installation everything works OK but as soon as we installed Windows SDK the build fails in TF2 (now it fails in Release build too).

@wjwwood says: It might also be possible to change these constants in ROS 2 (with appropriate special handling in the ros1_bridge).

dejanpan avatar Oct 27 '17 02:10 dejanpan

This is also an issue with 'DELETE' defined in winnt.h: https://github.com/ros2/common_interfaces/issues/44

We'll either need some way to generically protect ourselves from some known set of conflicting strings or else have a blacklist of known strings that must be banned due to windows bad hygene in macro names.

Might it make sense to have a known set of potentially colliding macros that automatically get undefed in our code generators if a conflict is detected?

tfoote avatar Oct 27 '17 07:10 tfoote

Options:

  • undefine Windows specific MACRO (preferrably only when the message actually uses that name)
  • name mangle the enum (e.g. appending an underscore)
  • use different enum naming scheme (e.g. kError)

dirk-thomas avatar Feb 27 '18 22:02 dirk-thomas

Related: https://github.com/ros2/design/pull/172

tfoote avatar Apr 30 '18 08:04 tfoote