简体   繁体   English

使用arm-none-eabi-gcc和bool变量的编译器错误

[英]Compiler error using arm-none-eabi-gcc and bool variables

I am trying to compile a usb loopback example for STM32 using arm-none-eabi-gcc but am stuck on a compiler error for bool variables. 我正在尝试使用arm-none-eabi-gcc编译STM32的usb环回示例,但由于布尔变量而陷入编译器错误。 The error is error: expected ';', identifier or '(' before '_Bool' and the offending lines are 错误是error: expected ';', identifier or '(' before '_Bool' ,并且冒犯的行是

typedef enum
{
  FALSE = 0, TRUE  = !FALSE
}
bool;

From what I've read, it seems bool is an alias for _Bool while gcc transitions to bool being an actual type. 根据我的阅读,似乎bool_Bool的别名,而gcc转换为bool是实际类型。 Unfortunately I have no idea how to fix this. 不幸的是,我不知道如何解决这个问题。 With some googling I've read that similar problems are sometimes related to having TRUE and FALSE defined elsewhere but I'm using largely unchanged code from STM and don't know of anywhere else they might be defined. 通过一些谷歌搜索,我已经读到类似的问题有时与在其他位置定义TRUEFALSE有关,但是我使用的是STM大致不变的代码,并且不知道它们可能在其他地方定义。 I've also read that it could be due to linking against libc but get the same error when compiling with -nostdlib . 我还读到它可能是由于针对libc进行链接,但使用-nostdlib编译时会-nostdlib相同的错误。 Is there anything I can do to narrow down this problem? 我有什么办法可以缩小这个问题? Thanks. 谢谢。

Since this typedef was trying to define a bool type and my compiler was trying to use the _Bool type, what I ended up doing was commenting out the typedef all together and just using 由于此typedef试图定义布尔类型并且我的编译器试图使用_Bool类型,所以我最终要做的就是一起注释掉typedef并仅使用

#define TRUE 1
#define FALSE 0

I'm not positive this solved the problem since I still can't get the usb device to enumerate, but the program now compiles. 我不能肯定这解决了问题,因为我仍然无法枚举USB设备,但是程序现在可以编译了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM