在两个3rd-party库中为uint32重新定义Typedef(C2371) [英] Typedef redefinition (C2371) for uint32 in two 3rd-party libraries

查看:111
本文介绍了在两个3rd-party库中为uint32重新定义Typedef(C2371)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我正在使用 Box2D

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;

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

jsotypes.h(Spidermonkey):typedef unsigned long 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?

我很感谢每一个提示!

推荐答案

您可以这样做:

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

由于typedef仅仅是一个别名,因此只要这些标头仅包含声明,就不会引起ODR冲突.如果存在使用uint32的(结构或内联函数)定义,则它违反ODR.尽管您的编译器可能不够智能,无法检测到此错误,但仍然可以正常工作.

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.

这篇关于在两个3rd-party库中为uint32重新定义Typedef(C2371)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆