错误:Xcode 中 c 函数的未知类型名称 BOOL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31454994/
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-15 07:29:11  来源:igfitidea点击:

Error :Unknown type name BOOL for c function in Xcode

iosobjective-ccxcode

提问by Vaibhav

I am building a static library which has some c functions (both .h and .m file) with return type bool, after adding it to my existing project I am getting Unknown Type name 'BOOL'. I tried importing stdbool.h but still I am getting same error.So can someone tell me right way to add c functions in Xcode project.The method definition looks like

我正在构建一个静态库,它有一些返回类型为 bool 的 c 函数(包括 .h 和 .m 文件),在将它添加到我现有的项目后,我得到了Unknown Type name 'BOOL'。我尝试导入 stdbool.h 但我仍然遇到同样的错误。所以有人可以告诉我在 Xcode 项目中添加 c 函数的正确方法。方法定义看起来像

BOOL isDeviceWorkingFine();

回答by Sourav Ghosh

In stdbool.h, the definition is provided as boolwhich is a MACRO which gets expanded to _Bool. The BOOLyou're using is not standard C.

在 中stdbool.h,定义被提供为boolwhich 是一个扩展为_Bool. 在BOOL你使用不规范C

If you want to use the standard definition provided by stdbool.h, you may want to change the BOOLto bool.

如果要使用 提供的标准定义stdbool.h,可能需要将 更改BOOLbool

Otherwise, you need to use some other specific header file, which actually provides the definition of BOOLfor your implementation.NOTE

否则,您需要使用其他一些特定的头文件,它实际上BOOL为您的实现提供了定义。笔记



NOTE: as mentioned in the commentsby Mr Blagovest Buyukliev, you may need <Foundation/Foundation.h>.

注:如在评论中提到的先生Blagovest Buyukliev,你可能需要<Foundation/Foundation.h>

回答by too honest for this site

The C standard since C99 defines _Boolas a keyword, along with _Trueand _False. stdint.hprovides macros with the C++ names bool, etc. to map to these keywords.

自 C99 以来的 C 标准定义_Bool为关键字,以及_True_Falsestdint.h提供带有 C++ 名称bool等的宏以映射到这些关键字。

Note that BOOLand boolare different names, as C is case-sensitive. So you should change BOOLto bool. Ifthat is not possible (e.g. if you use foreign libraries),

请注意,BOOLbool是不同的名称,因为 C 区分大小写。所以你应该BOOL改为bool. 如果这是不可能的(例如,如果您使用外国图书馆),

#include <stdbool.h>
#define BOOL bool

回答by Rohit suvagiya

It was broken Apple software.

它是损坏的Apple软件。

Apple disregarded my 3.2.6 projects settings and decided to use the LLVM 3.0 suite rather than GCC 4.2. Previously (under Xcode 3.2.6), I had specifically set the project to use GCC due to my extensive use of GCC warnings and flags.

Apple 无视我的 3.2.6 项目设置并决定使用 LLVM 3.0 套件而不是 GCC 4.2。以前(在 Xcode 3.2.6 下),由于我广泛使用 GCC 警告和标志,我专门将项目设置为使用 GCC。

After I changed 'Build Settings' -> 'Compile for C/C++/Objective' back to GCC 4.2, it worked.

在我将“构建设置”->“为 C/C++/Objective 编译”更改回 GCC 4.2 后,它起作用了。