Hi,
Is it possible to use C++ in ESP-IDF environment? I have made a simple class, and include .h and .cpp in the same directory as main file. What I understood is in order to make this work, first main file must be in cpp file type as well, thus I rename main.c to main.cpp but it produces the error below
Code: Select all
make[1]: Entering directory `/home/beng/esp32/esp-idf/projects/myapp/build/main'
xtensa-esp32-elf-c++ -DESP_PLATFORM -Og -g3 -Wpointer-arith -Werror -Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wall -ffunction-sections -fdata-sections -mlongcalls -nostdlib -MMD -MP -Og -std=gnu++11 -g3 -fno-exceptions -fstrict-volatile-bitfields -I/home/beng/esp32/esp-idf/projects/myapp/main/include -I/home/beng/esp32/esp-idf/components/bt/include -I/home/beng/esp32/esp-idf/components/driver/include -I/home/beng/esp32/esp-idf/components/esp32/include -I/home/beng/esp32/esp-idf/components/expat/port/include -I/home/beng/esp32/esp-idf/components/expat/include/expat -I/home/beng/esp32/esp-idf/components/freertos/include -I/home/beng/esp32/esp-idf/components/json/include -I/home/beng/esp32/esp-idf/components/json/port/include -I/home/beng/esp32/esp-idf/components/log/include -I/home/beng/esp32/esp-idf/components/lwip/include/lwip -I/home/beng/esp32/esp-idf/components/lwip/include/lwip/port -I/home/beng/esp32/esp-idf/components/lwip/include/lwip/posix -I/home/beng/esp32/esp-idf/components/mbedtls/port/include -I/home/beng/esp32/esp-idf/components/mbedtls/include -I/home/beng/esp32/esp-idf/components/newlib/include -I/home/beng/esp32/esp-idf/components/nghttp/port/include -I/home/beng/esp32/esp-idf/components/nghttp/include -I/home/beng/esp32/esp-idf/components/nvs_flash/include -I/home/beng/esp32/esp-idf/components/spi_flash/include -I/home/beng/esp32/esp-idf/components/tcpip_adapter/include -I/home/beng/esp32/esp-idf/projects/myapp/build/include/ -I. -c /home/beng/esp32/esp-idf/projects/myapp/main/./main.cpp -o main.o
/home/beng/esp32/esp-idf/projects/myapp/main/./main.cpp: In function 'int app_main()':
/home/beng/esp32/esp-idf/projects/myapp/main/./main.cpp:35:5: error: C99 designator 'ssid' outside aggregate initializer
};
^
/home/beng/esp32/esp-idf/projects/myapp/main/./main.cpp:35:5: error: C99 designator 'password' outside aggregate initializer
make[1]: Leaving directory `/home/beng/esp32/esp-idf/projects/myapp/build/main'
make[1]: *** [main.o] Error 1
make: *** [main-build] Error 2
When I try to comment the following code and compile
Code: Select all
tcpip_adapter_init();
ESP_ERROR_CHECK( esp_event_loop_init(event_handler, NULL) );
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ESP_ERROR_CHECK( esp_wifi_init(&cfg) );
ESP_ERROR_CHECK( esp_wifi_set_storage(WIFI_STORAGE_RAM) );
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
wifi_config_t sta_config = {
.sta = {
.ssid = "Cytron-Asus",
.password = "f5f4f3f2f1",
.bssid_set = false
}
};
ESP_ERROR_CHECK( esp_wifi_set_config(WIFI_IF_STA, &sta_config) );
ESP_ERROR_CHECK( esp_wifi_start() );
ESP_ERROR_CHECK( esp_wifi_connect() );
it gives following error
Code: Select all
/home/beng/esp32/esp-idf/projects/myapp/build/esp32/libesp32.a(cpu_start.o):(.literal.main_task+0x0): undefined reference to `app_main'
/home/beng/esp32/esp-idf/projects/myapp/build/esp32/libesp32.a(cpu_start.o): In function `main_task':
/home/beng/esp32/esp-idf/components/esp32/./cpu_start.c:169: undefined reference to `app_main'
collect2: error: ld returned 1 exit status
make: *** [/home/beng/esp32/esp-idf/projects/myapp/build/DHT22.elf] Error 1
Some libraries I believe they are written in C, so when should I include extern "C" {}?
Attached are the source files in main directory. The whole project I am using basic app-template provided by Espressif.
Hope you guys can enlighten me on how to solve this!