4

In my application I am using Box2D and Spidermonkey. Both libraries are defining the type uint32, which obviously gives me a compiler-error when using both in the same compilation unit.

b2settings.h (Box2D): typedef unsigned int uint32;

jsotypes.h (Spidermonkey): typedef unsigned long uint32;

Is there any way to resolve this collision without needing to change the headers of the 3rd-party libraries?

I am thankful for every hint!

rubenvb
  • 74,642
  • 33
  • 187
  • 332
CodeSalad
  • 1,375
  • 2
  • 14
  • 22

1 Answers1

4

You can do this hack:

#define uint32 Box2D_uint32
#include "Box2D.h"
#undef uint32
#define uint32 Spider_uint32
#include "Spidermonkey.h"
#undef uint32

Since typedef is merely an alias, this shouldn't cause ODR violation as long as these headers contain declarations only. If there is a (struct or inline function) definition that uses uint32, it will violate ODR. Although your compiler probably isn't smart enough to detect this and it still will work.

But a better choice is to report the problem to the library developers so they will fix that with, e.g. namespaces.

Yakov Galka
  • 70,775
  • 16
  • 139
  • 220