在MinGW中使用C时,我遇到了类似于“未知类型名称'uint8_t'”等的问题。
我该如何解决?
stdint.h
或 inttypes.h
。#include <stdint.h>
之前显式添加include <stdio.h>
。 - Peter Mortensenuint8_t
类型别名,您需要包含标准头文件stdint.h
。warning: incompatible implicit declaration of built-in function ‘printf’
,可能需要在 #include <stdint.h>
之前显式添加 #include <stdio.h>
。 - Peter Mortensen#include
顺序很重要,而且它不是你的设计模式的一部分(也就是说,你不知道为什么),那么你需要重新考虑你的设计。很可能,这只意味着你需要将导致问题的#include
添加到头文件中。#include
任何其他需要它的库接口之前,你需要#include
stdint.h
。
例子:
我的LCD库使用uint8_t类型。我写了一个带有接口(Display.h
)和实现(Display.c
)的库。#include <stdint.h>
#include <string.h>
#include <avr/io.h>
#include <Display.h>
#include <GlobalTime.h>
这是有效的。
然而,如果我像这样重新排列它们:
#include <string.h>
#include <avr/io.h>
#include <Display.h>
#include <GlobalTime.h>
#include <stdint.h>
Display.h
需要stdint.h
的信息,但是它无法访问,因为这些信息是在Display.h
编译完成之后才编译的。stdint.h
移到需要它的任何库的上面,就不会再出现此错误了。Display.h
应该包含 #include <stdint.h>
。不要依赖其他文件来替你包含内容,这就是头文件保护存在的原因。 - Jerska#include <stdint.h>
之前没有显式的 #include <stdio.h>
,则可能会出现警告:warning: incompatible implicit declaration of built-in function ‘printf’
。 - Peter Mortensen我必须包含 "PROJECT_NAME/osdep.h",这将包括特定于操作系统的配置。
我会查看使用您感兴趣的类型的其他文件,并查找它们是如何定义的(通过查看包含)。
stdint.h
头文件? - Necrolis