Conflict caused by #define macro and enum using the same name

I am trying to integrate NVIDIA PhysX into my Linux codebase. In some header files, it defines the following enumerations:

physxvisualdebuggersdk / PvdErrorCodes.h

struct PvdErrorType
{
  enum Enum
  {
    Success = 0,
    NetworkError,
    ArgumentError,
    InternalProblem
  };
};

      

physxprofilesdk / PxProfileCompileTimeEventFilter.h:

struct EventPriorities
{
  enum Enum
  {
    None,       // the filter setting to kill all events
    Coarse,
    Medium,
    Detail,
    Never       // the priority to set for an event if it should never fire.
  };
};

      

This results in the following compilation errors:

/usr/local/include/PhysX3/physxvisualdebuggersdk/PvdErrorCodes.h:36:4: error: expected identifier before numeric constant
    Success = 0,
    ^
/usr/local/include/PhysX3/physxvisualdebuggersdk/PvdErrorCodes.h:36:4: error: expected β€˜}’ before numeric constant
/usr/local/include/PhysX3/physxvisualdebuggersdk/PvdErrorCodes.h:36:4: error: expected unqualified-id before numeric constant

      

and

/usr/local/include/PhysX3/physxprofilesdk/PxProfileCompileTimeEventFilter.h:46:4: error: expected identifier before numeric constant
    None,  // the filter setting to kill all events
    ^
/usr/local/include/PhysX3/physxprofilesdk/PxProfileCompileTimeEventFilter.h:46:4: error: expected β€˜}’ before numeric constant
/usr/local/include/PhysX3/physxprofilesdk/PxProfileCompileTimeEventFilter.h:46:4: error: expected unqualified-id before numeric constant

      

I figured it was because X11 / Xh # defines both "No" and "Success". I confirmed that this is a problem, because if I #undef both "No" and "Success", I no longer have errors. However, this is obviously not a desirable thing.

My question is, as a developer who needs to use both of these headers, what is the correct course of action for me? Should I report this to NVIDIA as a bug and wait for a fix, or is there something I can do myself to fix the problem (besides #undef)?

Thank you for your time!

+3


source to share


1 answer


The smartest course of action is to split the implementations so that within your project you don't include BOTH conflicting headers in the same source file. One file deals with X and one with PhysX, and then your application links the two implementations together.



+1


source







All Articles