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

ThomasESP32
Posts: 191
Joined: Thu Jul 14, 2022 5:15 am

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

Postby ThomasESP32 » Mon Jan 16, 2023 2:13 pm

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

User avatar
gtjoseph
Posts: 81
Joined: Fri Oct 15, 2021 10:55 pm

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

Postby gtjoseph » Wed Jan 18, 2023 12:52 am

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.

User avatar
mbratch
Posts: 298
Joined: Fri Jun 11, 2021 1:51 pm

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

Postby mbratch » Fri Feb 03, 2023 7:56 pm

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()
{
    ....
}

Who is online

Users browsing this forum: No registered users and 20 guests