#author("2023-04-13T18:13:00+08:00","default:Admin","Admin")
#author("2023-04-13T18:13:14+08:00","default:Admin","Admin")
[[C]]

* error: control reaches end of non-void function [-Werror=return-type] [#l3eff77b]

缺少return

#codeprettify{{
return 0;
}}

* error: unknown type name 'bool' [#k8000770]

在C语言标准(C89)没有定义布尔类型,所以会报错。而C99提供了一个头文件<stdbool.h>定义了bool,true代表1,false代表0。只要导入stdbool.h,就能非常方便的操作布尔类型了。

#codeprettify{{
#include <stdbool.h>
}}

&color(red){注意:C语言 #include 的顺序会引发,有一些基础的定义都无法找到的问题};

* error: 'sprintf' may write a terminating nul past the end of the destination [-Werror=format-overflow=] [#q739f796]

chr数组长度不够

* 编译的时候没问题,但是ld build时报错 undefined reference to XXX [#kff533f9]

下面报错信息里面的 sntp_service_start 是app_datetime.c里面的函数,app_datetime.c编译没问题,但是最后ld时报错

问题的原因:including的head 文件的顺序导致的
问题的原因:include 的head 文件的顺序导致的

#codeprettify{{
$ make all
Toolchain path: /opt/xtensa-lx106-elf/bin/xtensa-lx106-elf-gcc
Toolchain version: esp-2020r3-49-gd5524c1
Compiler version: 8.4.0
Python requirements from D:_RTOS_SDK/requirements.txt are satisfied.
Project is not inside a git repository, or git repository has no commits
will not use 'git describe' to determine PROJECT_VER.
App "ESP8266" version: 1
CC build/main/app_datetime.o
CC build/main/app_main.o
CC build/main/app_wifi.o
AR build/main/libmain.a
Generating esp8266.project.ld
LD build/ESP8266.elf
d:/xtensa-lx106-elf/bin/ld.exe: D:/build/main\libmain.a(app_main.o):(.literal.app_main+0x74): undefined reference to `sntp_service_start'
d:/xtensa-lx106-elf/bin/ld.exe: D:/build/main\libmain.a(app_main.o): in function `app_main':
D:/main/app_main.c:357: undefined reference to `sntp_service_start'
d:/xtensa-lx106-elf/bin/ld.exe: D:/build/main\libmain.a(app_wifi.o): in function `wifi_init_sta':
D:/main/app_wifi.c:487: undefined reference to `sntp_service_start'
collect2.exe: error: ld returned 1 exit status
make: *** [D:_RTOS_SDK/make/project.mk:510:/home/Administrator/esp/ESP8266/build/ESP8266.elf] 错误 1
}}

#hr();
コメント:
#comment_kcaptcha

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS