首页 > 解决方案 > 尝试在 ldebug.c 中包含 httpclient.h 会导致编译期间出错

问题描述

我的目标是通过包含 httpclient 在 ldebug.c 中执行 http post 请求。它在 dbg_printf.c 中有效,但在 ldebug.c 中出现编译错误。

In file included from ../ldebug.c:28:0:
../../http/httpclient.h:69:24: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'http_request'
 void ICACHE_FLASH_ATTR http_request(const char * url, const char * method, const char * headers, const char * post_data, http_callback_t callback_handle, int redirect_follow_count);

还有另一种方法可以进行发布请求吗?

标签: luaesp8266nodemcufirmware

解决方案


ICACHE_FLASH_ATTR是文件c_types.h中定义的宏

没有定义的原因有两个。

首先,ldebug.c 可能不包含 c_types.h 或包含 #includes c_types.h 的文件。这很容易修复 - 编辑 ldebug.c 并添加

#include <c_types.h>

#include <httpclient.h>

另一种可能性是ICACHE_FLASH编译 ldebug.c 时未定义符号。文件 c_types.h 仅定义ICACHE_FLASH_ATTR是否ICACHE_FLASH为 #define'd。如果第一个修复不起作用,则需要确保#define ICACHE_FLASH在编译 ldebug.c 时

最简单的方法是添加

#define ICACHE_FLASH 1

作为 ldebug.c 的第一行

或者,您可以确保-DICACHE_FLASH=1在任何开发环境中都设置为编译器标志。更改 ldebug.c 几乎可以肯定是更简单的方法。


推荐阅读