PlatformIO Community

Arduino library compile errors in PIO, yet again

A number of the Arduino libraries, when installed in PIO in the standard way, throw compile errors when the PIO compiler gets a hold of them, some of them fatal. Yes, yes I know, the Arduino implementation of the language is not a ““REAL C++”” language. But, come on, they are mostly developed by very experienced or professional programmers, and they should be allowed to work as is. The Arduino IDE seems to be smart enough to cope with them, but PIO is not.

Is there any way to tone down the lofty standards of the PIO C++ implementation to make PIO more useful for Arduino? Having standard Arduino examples work fine on the Arduino IDE, and then fail miserably on PIO is totally unacceptable. Anyone care? My latest example is the ESP32 Mail Client library, which fails to compile. Might be related to a structure defined in one .h being referenced in another .h, but I’m not smart enough to know, really.

Can you post the example sketch and platformio.ini that isn’t working? I haven’t had any issues with Arduino libraries not working PlatformIO.

PIO is 1:1 compatible with Arduino IDE examples language-wise. If you give it an .ino file from the Arduino IDE, it will auto-convert it to a valid .cpp file like, just like the Arduino IDE. If you give it a .cpp file, it is not transformed. If you give it an original .ino files as a .cpp file, you will need to do the conversion as the FAQ says to prevent errors.

So I’m taking you’re looking at https://platformio.org/lib/show/6221/ESP32%20Mail%20Client. Take the Send_email.ino example, for example. Just copy that file into the src/ folder, along with its needed image.h file (can also be found in their github). Install the library as the “Installation” page at PlatformIO shows by adding

lib_deps = 
   ESP32 Mail Client

into your platformio.ini. Then hit “Build”.

Processing esp32dev (platform: espressif32; board: esp32dev; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/esp32dev.html
PLATFORM: Espressif 32 1.12.4 > Espressif ESP32 Dev Module
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (esp-prog) External (esp-prog, iot-bus-jtag, jlink, minimodule, olimex-arm-usb-ocd, olimex-arm-usb-ocd-h, olimex-arm-usb-tiny-h, olimex-jtag-tiny, tumpa)
PACKAGES:
 - framework-arduinoespressif32 3.10004.200129 (1.0.4)
 - tool-esptoolpy 1.20600.0 (2.6.0)
 - toolchain-xtensa32 2.50200.80 (5.2.0)
Converting Send_email.ino
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 31 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <ESP32 Mail Client> 2.1.4
|   |-- <WiFi> 1.0
|   |-- <HTTPClient> 1.2
|   |   |-- <WiFi> 1.0
|   |   |-- <WiFiClientSecure> 1.0
|   |   |   |-- <WiFi> 1.0
|   |-- <FS> 1.0
|   |-- <SD(esp32)> 1.0.5
|   |   |-- <FS> 1.0
|   |   |-- <SPI> 1.0
|   |-- <SPI> 1.0
|   |-- <SPIFFS> 1.0
|   |   |-- <FS> 1.0
|-- <SD(esp32)> 1.0.5
|   |-- <FS> 1.0
|   |-- <SPI> 1.0
Building in release mode
Compiling .pio\build\esp32dev\src\Send_email.ino.cpp.o
Generating partitions .pio\build\esp32dev\partitions.bin
Compiling .pio\build\esp32dev\libd8c\WiFi\ETH.cpp.o
Compiling .pio\build\esp32dev\libd8c\WiFi\WiFi.cpp.o
Compiling .pio\build\esp32dev\libd8c\WiFi\WiFiAP.cpp.o
Compiling .pio\build\esp32dev\libd8c\WiFi\WiFiClient.cpp.o
Compiling .pio\build\esp32dev\libd8c\WiFi\WiFiGeneric.cpp.o
Compiling .pio\build\esp32dev\libd8c\WiFi\WiFiMulti.cpp.o
Compiling .pio\build\esp32dev\libd8c\WiFi\WiFiSTA.cpp.o
Compiling .pio\build\esp32dev\libd8c\WiFi\WiFiScan.cpp.o
Compiling .pio\build\esp32dev\libd8c\WiFi\WiFiServer.cpp.o
Compiling .pio\build\esp32dev\libd8c\WiFi\WiFiUdp.cpp.o
Compiling .pio\build\esp32dev\lib429\WiFiClientSecure\WiFiClientSecure.cpp.o
Compiling .pio\build\esp32dev\lib429\WiFiClientSecure\ssl_client.cpp.o
Compiling .pio\build\esp32dev\lib283\HTTPClient\HTTPClient.cpp.o
Compiling .pio\build\esp32dev\lib6ad\FS\FS.cpp.o
Compiling .pio\build\esp32dev\lib6ad\FS\vfs_api.cpp.o
Compiling .pio\build\esp32dev\lib179\SPI\SPI.cpp.o
Compiling .pio\build\esp32dev\lib982\SD\SD.cpp.o
Compiling .pio\build\esp32dev\lib982\SD\sd_diskio.cpp.o
Compiling .pio\build\esp32dev\lib982\SD\sd_diskio_crc.c.o
Compiling .pio\build\esp32dev\liba96\SPIFFS\SPIFFS.cpp.o
Compiling .pio\build\esp32dev\lib4c4\ESP32 Mail Client_ID6221\ESP32MailHTTPClient.cpp.o
Compiling .pio\build\esp32dev\lib4c4\ESP32 Mail Client_ID6221\ESP32TimeHelper.cpp.o
Archiving .pio\build\esp32dev\lib6ad\libFS.a
Archiving .pio\build\esp32dev\lib429\libWiFiClientSecure.a
Archiving .pio\build\esp32dev\libd8c\libWiFi.a
Archiving .pio\build\esp32dev\lib179\libSPI.a
Compiling .pio\build\esp32dev\lib4c4\ESP32 Mail Client_ID6221\ESP32_MailClient.cpp.o
Compiling .pio\build\esp32dev\lib4c4\ESP32 Mail Client_ID6221\RFC2047.cpp.o
Compiling .pio\build\esp32dev\lib4c4\ESP32 Mail Client_ID6221\WiFiClientSecureESP32.cpp.o
Compiling .pio\build\esp32dev\lib4c4\ESP32 Mail Client_ID6221\ssl_client32.cpp.o
Archiving .pio\build\esp32dev\libFrameworkArduinoVariant.a
Indexing .pio\build\esp32dev\lib6ad\libFS.a
Indexing .pio\build\esp32dev\lib179\libSPI.a
Indexing .pio\build\esp32dev\lib429\libWiFiClientSecure.a
Indexing .pio\build\esp32dev\libd8c\libWiFi.a
Indexing .pio\build\esp32dev\libFrameworkArduinoVariant.a
Compiling .pio\build\esp32dev\FrameworkArduino\Esp.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\FunctionalInterrupt.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\HardwareSerial.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\IPAddress.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\IPv6Address.cpp.o
Archiving .pio\build\esp32dev\lib283\libHTTPClient.a
Compiling .pio\build\esp32dev\FrameworkArduino\MD5Builder.cpp.o
Indexing .pio\build\esp32dev\lib283\libHTTPClient.a
Compiling .pio\build\esp32dev\FrameworkArduino\Print.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\Stream.cpp.o
Archiving .pio\build\esp32dev\lib982\libSD.a
Compiling .pio\build\esp32dev\FrameworkArduino\StreamString.cpp.o
Indexing .pio\build\esp32dev\lib982\libSD.a
Compiling .pio\build\esp32dev\FrameworkArduino\WMath.cpp.o
Archiving .pio\build\esp32dev\liba96\libSPIFFS.a
Indexing .pio\build\esp32dev\liba96\libSPIFFS.a
Compiling .pio\build\esp32dev\FrameworkArduino\WString.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\base64.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\cbuf.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-adc.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-bt.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-cpu.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-dac.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-gpio.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-i2c.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-ledc.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-matrix.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-misc.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-psram.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-rmt.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-sigmadelta.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-spi.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-time.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-timer.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-touch.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\esp32-hal-uart.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\libb64\cdecode.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\libb64\cencode.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\main.cpp.o
Compiling .pio\build\esp32dev\FrameworkArduino\stdlib_noniso.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\wiring_pulse.c.o
Compiling .pio\build\esp32dev\FrameworkArduino\wiring_shift.c.o
Archiving .pio\build\esp32dev\libFrameworkArduino.a
Indexing .pio\build\esp32dev\libFrameworkArduino.a
Archiving .pio\build\esp32dev\lib4c4\libESP32 Mail Client_ID6221.a
Indexing .pio\build\esp32dev\lib4c4\libESP32 Mail Client_ID6221.a
Linking .pio\build\esp32dev\firmware.elf
Building .pio\build\esp32dev\firmware.bin
Retrieving maximum program size .pio\build\esp32dev\firmware.elf
Checking size .pio\build\esp32dev\firmware.elf
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
RAM:   [=         ]  12.5% (used 40856 bytes from 327680 bytes)
Flash: [=======   ]  74.4% (used 975274 bytes from 1310720 bytes)
esptool.py v2.6
======================== [SUCCESS] Took 21.87 seconds ========================

And it tells us that

Converting Send_email.ino

it converted the ino file by itself, no user interaction needed, and has completed compilation perfectly fine. I don’t yet see that “totally unaccepable” behavior of PlatformIO you see, please post your error message.

Thanks for those insights on .ino file conversion.

Turns out my problem was caused by a certain rogue library (ArduinoHTTPClient) which was installed in both my Arduino libraries folder, and also in PIO as a Global library. The compile/link on the Arduino IDE apparently ignored this library and used the built-in HTTPClient and it worked just fine. The compile on PIO apparently used this library and failed to compile correctly. I deleted this library in both places, and now both compile/links work fine.

Seems like the best way forward for me is to delete all global libraries in PIO, and add back only the ones needed for a given project as project libraries. Part of my problem as a newbie was that the big blue Install button in the PIO library manager installs the library as a global, exactly the wrong thing to do as a best practice.

So I posted a thread in the Adafruit forum here
https://forums.adafruit.com/viewtopic.php?f=56&t=167263
which sparks my interest in all this. As the link explains, I use a certain library from Adafruit called AdafruitIO. When I install that library using the PlatformIO library manager, some 21 additional libraries automatically install as well, apparently to support the library examples which also automatically download to PlatformIO. A number of these libraries (developed, I presume, by professional C++ programmers from Adafruit) have fatal compiler errors using the PlatformIO C++ compiler and its STANDARDS OF C++ PERFECTION. I have to manually delete, one at a time, all the “pile-on” libraries, as I call them to get the single library I want. If I update that library, all 22 libraries reinstall again, and it’s de je vu all over again. The Arduino IDE ignores these additional libraries if they are not used by the sketch being compiled, but PlatformIO dutifully compiles them all and flags the fatal C++ errors and stops dead until I delete all 21 of them from my project. I have some 12 projects in PlatformIO now where this horror repeats, because I install all libraries as Project libraries, as recommended. Am I using PlatformIO incorrectly? Is there a work-around to stop the 21 unused Adafruit libraries from installing? Please don’t tell me to change policies at Adafruit–they are bigger and more important to me than PlatformIO. You must operate in the environment you are dealt.