app_main call C++
Posted: Fri Feb 17, 2017 8:12 am
by pcbreflux
Hi,
here a small C++ example howto build a C++ firmware including app_main.
https://github.com/pcbreflux/espressif/ ... _cpp_hello
Re: app_main call C++
Posted: Wed Mar 15, 2017 6:31 pm
by mjmorrison
Hi,
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();
}
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.
Re: app_main call C++
Posted: Wed Mar 15, 2017 6:45 pm
by martinayotte
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 !
Re: app_main call C++
Posted: Thu Mar 16, 2017 8:25 am
by ESP_igrr
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.