尝试构建用于发布的 XCode 项目时出现 Typedef 重定义错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9995780/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:52:20  来源:igfitidea点击:

Typedef redefinition error when trying to build XCode project for release

xcodetypedefredefinitionllvm-3.0

提问by ivan glisic

I can build my project in Xcode(4.2) for debugging without issues, but when I want to build it for release (build for archiving) I get error:"Typedef redefinition with different types (unsigned int vs unsigned long)".

我可以在 Xcode(4.2) 中构建我的项目以进行调试而不会出现问题,但是当我想构建它以进行发布(构建用于存档)时,我收到错误消息:“不同类型的 Typedef 重新定义(unsigned int 与 unsigned long)”。

Problematic code is:

有问题的代码是:

#ifdef _LZMA_UINT32_IS_ULONG 
typedef long Int32; 
typedef unsigned long UInt32; 
#else 
typedef int Int32; 
typedef unsigned int UInt32; <--error on this line
#endif

You can see whole file on: http://read.pudn.com/downloads166/sourcecode/zip/758136/C/Types.h__.htm

您可以在以下位置查看整个文件:http: //read.pudn.com/downloads166/sourcecode/zip/758136/C/Types.h__.htm

Previous definition is in MacTypes.h from CoreServices framework.

以前的定义在 CoreServices 框架的 MacTypes.h 中。

I have the same preprocessor macros for Debug and Release, and I am using Apple's LLVM compiler 3.0. Same error happens when I try to build project for analyzing.

我有相同的调试和发布预处理器宏,我使用的是 Apple 的 LLVM 编译器 3.0。当我尝试构建项目进行分析时,也会发生同样的错误。

Any idea why this is happening?

知道为什么会这样吗?

回答by DRVic

In the case where you're getting the error (when compiling 32 bit) you already have the equivalent of

如果您遇到错误(编译 32 位时),您已经拥有了

typedef unsigned int UInt32; <--error on this line

(hence the error) So you can delete the offending line.

(因此出现错误)因此您可以删除违规行。

Apparently not all of your source includes / imports MacTypes.h, so to have it both ways, surround the offending line with #ifdefs like so:

显然,并非您的所有源代码都包含/导入 MacTypes.h,因此要双向使用,请用 #ifdefs 包围违规行,如下所示:

#ifndef __MACTYPES__
typedef unsigned int UInt32;
#endif

Unfortunately this is not perfect; you need to be sure that if MacTypes.h is included, it happens before this. One way to ensure that is to do your system #imports before your local #imports.

不幸的是,这并不完美;您需要确保如果包含 MacTypes.h,它会在此之前发生。确保这一点的一种方法是在本地 #imports 之前执行系统 ​​#imports。