尝试使用简单的附加功能扩展这个项目 - 进行 HTTP GET 调用。
CMakeLists.txt
文件存在且包含以下内容FILE(GLOB_RECURSE app_sources "./src/*.c")
idf_component_register(
SRCS ${app_sources}
INCLUDE_DIRS "./include"
REQUIRES esp_http_client esp-tls json
)
#include <http_rest_client.h>
,特别是在 main\apps\app_temp_demo\gui\gui_temp_demo.cpp
void sendrequest()
{
http_rest_recv_buffer_t response_buffer = {0};
// do the request
ESP_ERROR_CHECK(http_rest_client_get("https://catoftheday.com/", &response_buffer));
char buffer[50]; // Buffer to hold the resulting string
int status_code = response_buffer.status_code; // Your status code
sprintf(buffer, "Status Code %d", status_code); // Write to buffer
// print response status
// sprintf("Status Code %d", response_buffer.status_code);
// do something with the data
printf("%s", response_buffer.buffer);
// clean up
http_rest_client_cleanup(&response_buffer);
}
到目前为止,构建项目(
idf.py build
)是成功的,不幸的是,一旦我添加对 hte sendrequest 函数的调用,我就会收到以下警告/错误:
感觉图书馆没有捡起来建起来。关于我可能缺少的内容或可能更好的方法(即不同的库等)有什么建议吗?
在扫描了您引用的项目后,我觉得您错过了
extern C
,因此您想在 C
项目中使用 C++
库。extern "C"{
#include <http_rest_client.h>
}
应该有帮助。 或者,您可以调整引用组件的头文件。