消息“未知类型名称‘uint8_t’”在MinGW中
我在 MinGW 中使用 C 得到“未知类型名称 'uint8_t'” 和其他类似的信息。
我该如何解决这个问题?
I get "unknown type name 'uint8_t'" and others like it using C in MinGW.
How can I solve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试包含
stdint.h
或inttypes.h
。Try including
stdint.h
orinttypes.h
.要使用
uint8_t
类型别名,您必须包含stdint.h
标准标头。To use the
uint8_t
type alias, you have to include thestdint.h
standard header.需要明确:如果您的
#include
的顺序很重要,并且它不是您设计模式的一部分(请阅读:您不知道为什么),那么您需要重新思考你的设计。最有可能的是,这只是意味着您需要将#include
添加到头文件中,从而导致问题。在这一点上,我对讨论/捍卫该示例的优点没什么兴趣,但我将保留它,因为它说明了编译过程中的一些细微差别以及它们为何会导致错误。
您需要在
#include
任何其他需要它的库接口之前#include
stdint.h。示例:
我的 LCD 库使用 uint8_t 类型。我用接口 (
Display.h
) 和实现 (Display.c
) 编写了我的库。在 display.c 中,我有以下内容。
这有效。
但是,如果我像这样重新排列它们:
我会收到您描述的错误。这是因为
Display.h
需要来自stdint.h
的内容,但它无法访问它,因为该信息是在 Display.h 之后编译的。已编译。因此,将
stdint.h
移到任何需要它的库上方,您就不会再收到错误了。To be clear: If the order of your
#include
s matters and it is not part of your design pattern (read: you don't know why), then you need to rethink your design. Most likely, this just means you need to add the#include
to the header file causing problems.At this point, I have little interest in discussing/defending the merits of the example, but I will leave it up as it illustrates some nuances in the compilation process and why they result in errors.
You need to
#include
thestdint.h
before you#include
any other library interfaces that need it.Example:
My LCD library uses uint8_t types. I wrote my library with an interface (
Display.h
) and an implementation (Display.c
).In display.c, I have the following includes.
And this works.
However, if I rearrange them like so:
I get the error you describe. This is because
Display.h
needs things fromstdint.h
, but it can't access it because that information is compiled after Display.h is compiled.So move
stdint.h
above any library that needs it and you shouldn't get the error any more.我必须包含“PROJECT_NAME/osdep.h”,其中包括特定于操作系统的配置。
我会使用您感兴趣的类型查看其他文件,并找到它们的定义位置/方式(通过查看包含)。
I had to include "PROJECT_NAME/osdep.h" and that includes the OS-specific configurations.
I would look in other files using the types you are interested in and find where/how they are defined (by looking at includes).