Using CMake with esp-idf-v3.2.2. I am trying to embed a index.html file. Embedding files was so easy using make. Switching over to CMake i have not had any luck in doing so. Following the docs does not work for me.
Here is the doc reference.
https://docs.espressif.com/projects/esp ... inary-data
The main trouble is i get this in the following when compiling.
Code: Select all
(.rodata.embedded+0x0): multiple definition of `index_html'
main/libmain.a(hello_world_main.c.obj):(.data.index_html+0x0): first defined here
Here is the full result of the attempt to compile.
Code: Select all
C:\Users\Mike\ESP32\Source\hello_world>idf.py build size
Note: You are using Python 3.7.3. Python 3 support is new, please report any problems you encounter. Search for 'Setting the Python Interpreter' in the ESP-IDF docs if you want to use Python 2.7.
Checking Python dependencies...
Python requirements from C:\Users\Mike\ESP32\esp-idf\requirements.txt are satisfied.
Running ninja in directory C:\Users\Mike\ESP32\Source\hello_world\build
Executing "ninja all"...
[1/5] Performing build step for 'bootloader'
ninja: no work to do.
[2/3] Linking CXX executable hello-world.elf
FAILED: hello-world.elf
cmd.exe /C "cd . && C:\Users\Mike\.espressif\tools\xtensa-esp32-elf\1.22.0-80-g6c4433a5-5.2.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -nostdlib CMakeFiles/hello-world.elf.dir/dummy_main_src.c.obj -o hello-world.elf -Wl,--gc-sections -Wl,--cref -Wl,--Map=hello-world.map -Wl,--start-group soc/libsoc.a log/liblog.a heap/libheap.a xtensa-debug-module/libxtensa-debug-module.a app_trace/libapp_trace.a freertos/libfreertos.a vfs/libvfs.a newlib/libnewlib.a esp_ringbuf/libesp_ringbuf.a driver/libdriver.a esp_event/libesp_event.a ethernet/libethernet.a lwip/liblwip.a tcpip_adapter/libtcpip_adapter.a app_update/libapp_update.a spi_flash/libspi_flash.a mbedtls/libmbedtls.a micro-ecc/libmicro-ecc.a bootloader_support/libbootloader_support.a nvs_flash/libnvs_flash.a pthread/libpthread.a smartconfig_ack/libsmartconfig_ack.a wpa_supplicant/libwpa_supplicant.a esp32/libesp32.a cxx/libcxx.a asio/libasio.a jsmn/libjsmn.a coap/libcoap.a console/libconsole.a nghttp/libnghttp.a esp-tls/libesp-tls.a esp_adc_cal/libesp_adc_cal.a tcp_transport/libtcp_transport.a esp_http_client/libesp_http_client.a esp_http_server/libesp_http_server.a esp_https_ota/libesp_https_ota.a expat/libexpat.a wear_levelling/libwear_levelling.a sdmmc/libsdmmc.a fatfs/libfatfs.a freemodbus/libfreemodbus.a json/libjson.a libsodium/liblibsodium.a mdns/libmdns.a mqtt/libmqtt.a openssl/libopenssl.a protobuf-c/libprotobuf-c.a protocomm/libprotocomm.a spiffs/libspiffs.a ulp/libulp.a wifi_provisioning/libwifi_provisioning.a main/libmain.a -lgcov -Wl,--undefined=uxTopUsedPriority -L C:/Users/Mike/ESP32/esp-idf/components/newlib/lib -lc -lm -L C:/Users/Mike/ESP32/esp-idf/components/esp32/lib -L C:/Users/Mike/ESP32/esp-idf/components/esp32/ld/wifi_iram_opt -lcoexist -lcore -lespnow -lmesh -lnet80211 -lphy -lpp -lrtc -lsmartconfig -lwpa2 -lwpa -lwps -L C:/Users/Mike/ESP32/Source/hello_world/build/esp32 -T esp32_out.ld -L C:/Users/Mike/ESP32/esp-idf/components/esp32/ld -T esp32.common.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.libgcc.ld -T esp32.rom.spiram_incompatible_fns.ld C:/Users/Mike/ESP32/esp-idf/components/esp32/libhal.a -lgcc -u call_user_start_cpu0 -u ld_include_panic_highint_hdl -lstdc++ -u __cxa_guard_dummy -u __cxx_fatal_exception && cd ."
main/libmain.a(index.html.S.obj): In function `index_html':
(.rodata.embedded+0x0): multiple definition of `index_html'
main/libmain.a(hello_world_main.c.obj):(.data.index_html+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
ninja failed with exit code 1
C:\Users\Mike\ESP32\Source\hello_world>
Code: Select all
set(COMPONENT_SRCS hello_world_main.c)
set(COMPONENT_ADD_INCLUDEDIRS "")
set(COMPONENT_EMBED_TXTFILES index.html)
register_component()
This is my program.
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include <esp_log.h>
#include <esp_http_server.h>
#include "esp_http_client.h"
#include "lwip/apps/sntp.h"
#include "esp_err.h"
extern const uint8_t index_html_start[] asm("_binary_index_html_start");
extern const uint8_t index_html_end[] asm("_binary_index_html_end");
httpd_handle_t WEB_server = NULL;
// Send index.html Page
esp_err_t index_html_handler(httpd_req_t *req)
{
httpd_resp_set_type(req, "text/html");
httpd_resp_send(req, (const char *)index_html_start, index_html_end - index_html_start);
return ESP_OK;
}
//
httpd_uri_t index_html = {
.uri = "/",
.method = HTTP_GET,
.handler = index_html_handler,
/* Let's pass response string in user
* context to demonstrate it's usage */
.user_ctx = NULL
};
//
//
httpd_handle_t start_webserver(void)
{
httpd_config_t config = HTTPD_DEFAULT_CONFIG();
// Start the httpd server
ESP_LOGI("OTA", "Starting server on port: '%d'", config.server_port);
if (httpd_start(&WEB_server, &config) == ESP_OK)
{
// Set URI handlers
ESP_LOGI("OTA", "Registering URI handlers");
httpd_register_uri_handler(WEB_server, &index_html);
return WEB_server;
}
ESP_LOGI("OTA", "Error starting server!");
return NULL;
}
//
//
void app_main()
{
printf("Hello world!\n");
start_webserver();
}