app_main call C++

User avatar
pcbreflux
Posts: 28
Joined: Sat Feb 11, 2017 1:00 am
Location: germany
Contact:

app_main call C++

Postby pcbreflux » Fri Feb 17, 2017 8:12 am

Hi,

here a small C++ example howto build a C++ firmware including app_main.

https://github.com/pcbreflux/espressif/ ... _cpp_hello

mjmorrison
Posts: 26
Joined: Thu Nov 03, 2016 9:06 pm

Re: app_main call C++

Postby mjmorrison » Wed Mar 15, 2017 6:31 pm

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.

User avatar
martinayotte
Posts: 141
Joined: Fri Nov 13, 2015 4:27 pm

Re: app_main call C++

Postby martinayotte » Wed Mar 15, 2017 6:45 pm

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 !

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: app_main call C++

Postby ESP_igrr » Thu Mar 16, 2017 8:25 am

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 23 guests