gpt4 book ai didi

c++ - 第 3 方库冲突定义/重新定义

转载 作者:太空狗 更新时间:2023-10-29 21:46:25 24 4
gpt4 key购买 nike

我正在使用两个独立的库开发 Qt 平台。我面临的问题是他的两个库对 int32_t 有不同的声明。

第一个图书馆有:

#ifdef _WIN32
#if ULONG_MAX == 0xffffffff
typedef long int32_t;
#else
typedef int int32_t;
#endif
#endif

第二个图书馆:

typedef signed __int32    int32_t;
typedef unsigned __int32 uint32_t;

我得到的错误是:

C:\Program Files (x86)\SiliconSoftware\Runtime5.1\include\msinttypes\stdint.h:91: error: C2371: 'int32_t' : redefinition; different basic types c:\program files (x86)\matlab\r2008a\extern\include\mclmcr.h:216: see declaration of 'int32_t'

我尝试在 stackoverflow 上关注这篇文章:

Typedef redefinition (C2371) for uint32 in two 3rd-party libraries

我尝试在我的代码中实现它:

#define int32_t VicTorv3_int32_t
#include"mclmcr.h"
#undef int32_t
#define int32_t Silicon_int32_t
#include "stdint.h"
#undef int32_t

我仍然得到同样的错误。请帮忙。

最佳答案

stdint.h 也是一个系统包含文件。它很有可能在 define/undef 解决方法之前被包含在内。当您的解决方法尝试再次包含该文件时,包含保护程序会执行它们的工作。您可以使用以下方法检查情况: Displaying the #include hierarchy for a C++ file in Visual Studio

我建议将包含 stdint.h 的部分移动到文件的最顶部,在所有其他包含之前。

注意,用另一个版本隐藏系统包含文件 stdint.h 会出现问题。

关于c++ - 第 3 方库冲突定义/重新定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15266053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com