Hi Halfnium,
Thanks for documenting this. Just so you know, all of ESP-IDF's public headers should already have C++ header guards. If you find a header in ESP-IDF that doesn't have a guard, this is a bug so please report it. On the current ESP-IDF master branch I can change the attached hello_world_main.cpp as follows and it still links and runs correctly:
Code: Select all
#include <stdio.h>
#include "sdkconfig.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
extern "C" void app_main(void) {
printf("Hello C++ programming world!\n");
...
The only necessary addition is the 'extern "C"' in the declaration of app_main (as this function doesn't have a declaration in any header). I've combined the declaration line with the function definition to save space, but having it separate as you did is also totally fine.
If you find somewhere that linking fails on ESP-IDF, please let us know the version and the full linker error (including which symbol(s) fail to link), and we'll fix it.
Angus
PS There also some dedicated C++ examples in ESP-IDF, although we don't have an introductory "hello world" style one:
https://github.com/espressif/esp-idf/tr ... amples/cxx