错误:使用不同类型的 Typedef 重定义

error: typedef redefinition with different types

本文关键字:Typedef 定义 同类型 错误      更新时间:2023-10-16

我尝试使用 NDK 在 Android Studio 中编译 c++ 库,但出现一些错误:

C:AndroidSDKndk-bundletoolchainsllvmprebuiltwindows-x86_64bin..lib64clang3.8.275480includestddef.h:62:23: error: typedef redefinition with different types ('unsigned long' vs 'unsigned int') typedef __SIZE_TYPE__ size_t; ^../../../../src/main/cpp/includeCrypto/Core/Types.h:20:22: note: previous definition is here typedef unsigned int size_t;

当我定义

typedef unsigned long size_t;

我得到:

C:AndroidSDKndk-bundletoolchainsllvmprebuiltwindows-x86_64bin..lib64clang3.8.275480includestddef.h:62:23: error: typedef redefinition with different types ('unsigned int' vs 'unsigned long') typedef __SIZE_TYPE__ size_t;^  ../../../../src/main/cpp/includeCrypto/Core/Types.h:20:23: note: previous definition is here typedef unsigned long size_t;

我该如何解决它?

size_t已经是由几个 C/C++ 标准定义的数据类型。尝试键入定义语言中尚未定义的其他内容。

例:-

typedef unsigned long my_size_t;

不能使用 typedef 重新定义size_t 。如果要有一个 32 位无符号整数,可以编写:

typedef unsigned long u32t