Hi,
here a small C++ example howto build a C++ firmware including app_main.
https://github.com/pcbreflux/espressif/ ... _cpp_hello
app_main call C++
-
- Posts: 26
- Joined: Thu Nov 03, 2016 9:06 pm
Re: app_main call C++
Hi,
I'm looking at your "cpp_hellp.cpp" example, and I notice that you include some headers in a block like so.
Is it best practice you think to extern C the middle 3 includes? I have included them without issue without extern C, but I am pretty new to C/C++ and their interactions. Just wondering about the rationale behind this choice and thinking maybe I should be doing it that way as well.
I'm looking at your "cpp_hellp.cpp" example, and I notice that you include some headers in a block like so.
Code: Select all
extern "C"
{
#include "sdkconfig.h"
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
void app_main();
}
- martinayotte
- Posts: 141
- Joined: Fri Nov 13, 2015 4:27 pm
Re: app_main call C++
If you don't put 'extern "C" ' around plain C includes, the C++ will think that those functions are C++ and not plain C functions, therefore, at link time, it won't be able to include those functions from any libs, searching for their right signatures.
So, 'extern "C" ' are mandatory !
So, 'extern "C" ' are mandatory !
Re: app_main call C++
As a rule, we try to add C++ guards to all our ESP-IDF header files. So unless you are including a third party library (some of them don't have C++ guards), these extra guards should not be necessary.
Who is online
Users browsing this forum: No registered users and 13 guests