Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By rocket_man
#40132 When using some of the ESP8266 Arduino libraries, one needs to include them with extern "C" if they are C libraries. For example to include ip_addr.h, one needs to do it like this or it will not compile:

Code: Select allextern "C"{
#include "ip_addr.h"
}


For some of the other libraries, this is not needed (e.g., os_type.h).

My question is: how can one know if a library is a C library or a C++ library so that one knows to place it either inside the extern "C" block or outside? Thanks!
User avatar
By martinayotte
#40164 Arduino is in C++, while the Espressif SDK is in plain C.
So, the general rule is that any SDK includes need the "extern C".

BTW, why do you need to include the SDK "ip_addr.h" ?
Is there something you need that Arduino "ESP8266WiFi.h" and "IPAddress.h" don't provide ?
User avatar
By rocket_man
#40282 Thanks for the information, I'll keep that in mind when including any SDK libraries.

To answer your question, I was trying to stitch together some code examples I saw that would allow me to ping other devices with the ESP8266. The only code I found was using the ping.h library from the SDK, so the code snippets used the ip_addr.h include.

I actually wasn't aware of the Arduino IPAddress.h until you pointed it out, thanks! I checked it out, and it seems like that while it's a bit different, the same functionality is there. Namely, with ip_addr.h I can call ip_addr("192.168.0.1") and get a uint32 form that I need. With IPAddress.h I need to create an IPAddress object, use fromString to populate the _address field, and then use the overloaded cast to uint32. So the functionality is definitely there, but it seems like for this particular purpose, it's a few more lines of code. I'll switch over to using IPAddress.h though since it's already included when I include ESP8266WiFi.h. Thanks for the information!