Page 1 of 1

How to use C++ with ESP-IDF and FreeRTOS please ?

Posted: Mon Jan 16, 2023 2:13 pm
by ThomasESP32
Good afternoon,

I am using Eclipse CDT (ESP-IDF) in order to work with a ESP32-S3-DevKitC-1 EVM.
After creating a new project, I get a main.c main file for my application.

Instead of using a c file, I would like to use C++ in order to work with class.
So I renamed my main file main.cpp and decleared the app_main(void) function extern "C" app_main(void).

When I do this, I manage to execute the app_main function but when I want to use some of the methods provided by ESP-IDF, for example esp_chip_info(...), the compiler does not found some references anymore.
For example :
esp_chip_info_t chip_info; => I get the errors (Type esp_chip_info_t could not be resolved).
esp_chip_info(&chip_info); => I get the error invalid arguments

these two lines are oK when I use a main.c file instead of C++ file.

At the beginning ot my main.cpp file, I put the include files in a extern "C" { ..... }

Do you know how to solve this problem please ?

Best regards,

Thomas TRUILHE

Re: How to use C++ with ESP-IDF and FreeRTOS please ?

Posted: Wed Jan 18, 2023 12:52 am
by gtjoseph
At the beginning ot my main.cpp file, I put the include files in a extern "C" { ..... }
You should NOT use extern "C" { ..... } around any header files provided by esp-idf. They're already taken care of. If you still have issues after removing the extern "C" { ..... }, post back. It should just work without any other modifications.

Re: How to use C++ with ESP-IDF and FreeRTOS please ?

Posted: Fri Feb 03, 2023 7:56 pm
by mbratch
My whole application is in C++. The only thing you need to do is extern the main C entry point since ESP-IDF expects that to be a C function:

Code: Select all

extern "C" void app_main()
{
    ....
}