As of the library to determine for which platform / frameworks it is compiled

How to determine from a library which platform / frameworks it compiles for?
Earlier (in ArduinoIDE) I used the following construction:

#if defined(ESP32)
#include “bla-bla-bla-esp32.h”


#if defined(ESP8266)
#include “bla-bla-bla-esp8266.h”


This does not work in the PlatformIO!

Specifically, I need to define the frameworks “espidf”, “esp8266-rtos-sdk”

This does work in PlatformIO + Arduino.

platform = espressif32
board = esp32dev
framework = arduino

any compiler invocation has the flags (which you can also check by simply executing the “Verbose Build” task)


As you can see ESP32 is also in there.

However in ESP-IDF flags are different.

xtensa-esp32-elf-gcc -o .pio\build\esp32dev\esp-idf\app_update\esp_ota_ops.c.o -c -std=gnu99 -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -fstrict-volatile-bitfields -Wall -Werror=all
-Wno-error=unused-function -Wno-error=unused-but-set-variable -Wno-error=unused-variable -Wno-error=deprecated-declarations -Wextra -Wno-unused-parameter -Wno-sign-compare -ggdb -Og -Wno-old-style-declaration -DPLATFORMIO=50004 -DARDUINO_ESP32_DEV -DCONFIG_BLINK_GPIO=2 -D_GNU_SOURCE -DIDF_VER=“3.40100.200827” -DESP_PLATFORM …

So you can e.g. use ESP_PLATFORM or #ifdef IDF_VER.


platform = espressif8266
board = nodemcuv2
framework = esp8266-rtos-sdk

the Verbose Build shows that flags


Are used so this works still with #ifdef ESP8266.

Also note that libraries which have different library dependencies for each platform might need to set their libLDFMode value in the library.json to either chain+ or deep+.



What you need! THANKS !!!

No problem, marking as solved then.

Alas, but for some reason it didn’t work for me again :frowning:
Perhaps my PlatformIO was installed crookedly???
I installed it on three computers, and everywhere there were some problems during installation. Different everywhere.

If you could upload the whole project with the library that doesn’t work, we can take a look.

Good. Here is a library and a demo for it. They work great on ESP 32.

Now I want to adapt it for esp8266 (for FreeRtos, of course)

Thanks for your help and support. Checked build verbose. Result in the picture:


For some reason, there is an ARDUINO_ESP32_DEV define (although the project is only for ESPIDF), but not just ESP32. It remains to be seen why.

My demo above showed ESP32 with the Arduino platform. In the text above I explained that for ESP-IDF, other macros must be used, e.g. IDF_VER. Changing #ifdef ESP32 to #ifdef IDF_VER, and deleting an errornous #else in rLed32.h line 120 makes the project compile.


Now I understand, thank you very much

Replaced with
#if defined(IDF_VER) || defined(ESP32)

It works. Thanks again