|
RT-Thread添加软件包会出现uint8_t uint16_t uint32_t size_t NULL未定义错误
描述:
RT-Thread添加软件包会出现uint8_t uint16_t uint32_t size_t未定义
大致出错内容,如下:
riscv64-unknown-elf-gcc "../applications/blehr_app.c"
../applications/blehr_app.c:25:40: error: unknown type name 'uint16_t'; did you mean 'rt_uint16_t'?
25 | void bthw_get_heap_info(void **p_heap, uint16_t **p_heap_size, uint32_t *p_block_size);
| ^~~~~~~~
| rt_uint16_t
../applications/blehr_app.c:25:64: error: unknown type name 'uint32_t'; did you mean 'rt_uint32_t'?
25 | void bthw_get_heap_info(void **p_heap, uint16_t **p_heap_size, uint32_t *p_block_size);
| ^~~~~~~~
| rt_uint32_t
../applications/blehr_app.c:26:73: error: unknown type name 'uint32_t'; did you mean 'rt_uint32_t'?
26 | typedef void (*nsmem_cb_init_func)(void *heap_buf, void *heap_size_buf, uint32_t mem_block_max);
| ^~~~~~~~
| rt_uint32_t
../applications/blehr_app.c: In function 'btctrl_mem_init':
../applications/blehr_app.c:32:5: error: unknown type name 'uint16_t'; did you mean 'rt_uint16_t'?
32 | uint16_t *heap_size_buf;
| ^~~~~~~~
| rt_uint16_t
../applications/blehr_app.c:33:5: error: unknown type name 'uint32_t'; did you mean 'rt_uint32_t'?
33 | uint32_t block_size;
| ^~~~~~~~
| rt_uint32_t
../applications/blehr_app.c:35:5: warning: implicit declaration of function 'bthw_get_heap_info' [-Wimplicit-function-declaration]
35 | bthw_get_heap_info(&heap_buf, &heap_size_buf, &block_size);
| ^~~~~~~~~~~~~~~~~~
../applications/blehr_app.c:27:27: error: 'nsmem_cb_init_func' undeclared (first use in this function); did you mean 'nsmem_cb_init'?
27 | #define nsmem_cb_init ((nsmem_cb_init_func)0x84140)
| ^~~~~~~~~~~~~~~~~~
../applications/blehr_app.c:36:5: note: in expansion of macro 'nsmem_cb_init'
36 | nsmem_cb_init(heap_buf, heap_size_buf, block_size);
| ^~~~~~~~~~~~~
../applications/blehr_app.c:27:27: note: each undeclared identifier is reported only once for each function it appears in
27 | #define nsmem_cb_init ((nsmem_cb_init_func)0x84140)
| ^~~~~~~~~~~~~~~~~~
../applications/blehr_app.c:36:5: note: in expansion of macro 'nsmem_cb_init'
36 | nsmem_cb_init(heap_buf, heap_size_buf, block_size);
| ^~~~~~~~~~~~~
../applications/blehr_app.c:27:46: error: expected ')' before numeric constant
27 | #define nsmem_cb_init ((nsmem_cb_init_func)0x84140)
| ~ ^~~~~~~
../applications/blehr_app.c:36:5: note: in expansion of macro 'nsmem_cb_init'
36 | nsmem_cb_init(heap_buf, heap_size_buf, block_size);
| ^~~~~~~~~~~~~
make: *** [applications/subdir.mk:24: applications/blehr_app.o] Error 1
"make -j4 all2" terminated with exit code 2. Build might be incomplete.
原因:
RT-Thread定义数据类型,使用rt前缀,如rt_uint8_t rt_uint16_t rt_uint32_t rt_size_t等
而开源代码是的大家常用,标准C库定义的uint8_t uint16_t uint32_t size_t数据类型
RT-Thread移植未改过来数据类型定义,头文件也没有加
解决方法:
添加头文件
#include <stdint.h>
#include <stddef.h>
当然添加上面的头文件,不能解决所有问题,像这个问题,就要自己在代码里找了. RT-Thread Studio 方法: 双击错误内容, 在源码里选中这个变量,cltr+双击,定位到定义的位置, 把对应的的头文件加上即可.
千万不要像图中说的,删除掉,这样会影响功能的.
如果还找到定义头文件, 可以临时,注释掉, 让编译通过,也不能删除掉哦.
还有个方法, 没定义的话,自己定义一下, 也可以的. 不过这样话, 也有风险, 原本定义过的, 再定义会出错:重复定义.
还有很可能是配置时,少加载了驱动 \BSP\软件功能包, 这个方法比较复杂, 具体问题要具体分析. 要了解整个开源项目代码结构,相关依赖项目. 这种问题, 网上找答案, 或我们谷动谷力\RT-Thread\电子发烧友....等发贴资咨询. 也可以私信我们.
建议:
RT-Thread官可以统一用标准C库定义的uint8_t uint16_t uint32_t size_t数据类型, 使用我们的代码更有通用性。
大家写代码也用标准C库定义的uint8_t uint16_t uint32_t size_t数据类型,不用使用rt前缀,如rt_uint8_t rt_uint16_t rt_uint32_t rt_size_t NULL等
|
+10
|