PlatformIO Community

Can't understand PIO logic when building libraries

Good time.

I have several dozen of my own libraries for ESP32. All of them are in a separate folder from the project: c:\PlatformIO\libs, as they are used in several projects at once.

c:\PlatformIO\libs\certs\
c:\PlatformIO\libs\clouds\reMqtt\
c:\PlatformIO\libs\clouds\reNarodMon\
c:\PlatformIO\libs\clouds\reOpenMon\
c:\PlatformIO\libs\clouds\reTgSend\
c:\PlatformIO\libs\clouds\reThingSpeak\
c:\PlatformIO\libs\consts\
c:\PlatformIO\libs\peripherals\reAlarm\
c:\PlatformIO\libs\peripherals\reBeep\
c:\PlatformIO\libs\peripherals\reDS1307\
c:\PlatformIO\libs\peripherals\reElTariffs\
c:\PlatformIO\libs\peripherals\reGpio\
c:\PlatformIO\libs\peripherals\reLed\
c:\PlatformIO\libs\peripherals\reLedSys\
c:\PlatformIO\libs\peripherals\reLoadCtrl\
c:\PlatformIO\libs\peripherals\reMCP23017\
c:\PlatformIO\libs\peripherals\rePCF8574\
c:\PlatformIO\libs\peripherals\reRangeMonitor\
c:\PlatformIO\libs\peripherals\reRTC\
c:\PlatformIO\libs\peripherals\reRx433\
c:\PlatformIO\libs\sensors\reADC\
c:\PlatformIO\libs\sensors\reAHT1x\
c:\PlatformIO\libs\sensors\reAM232x\
c:\PlatformIO\libs\sensors\reBME68x\
c:\PlatformIO\libs\sensors\reBME280\
c:\PlatformIO\libs\sensors\reBMP280\
c:\PlatformIO\libs\sensors\reCCS811\
c:\PlatformIO\libs\sensors\reDHTxx\
c:\PlatformIO\libs\sensors\reDS18x20\
c:\PlatformIO\libs\sensors\reHTU2x\
c:\PlatformIO\libs\sensors\reMoisture\
c:\PlatformIO\libs\sensors\reSensor\
c:\PlatformIO\libs\sensors\reSHT3x\
c:\PlatformIO\libs\system\reCerts\
c:\PlatformIO\libs\system\reEsp32\
c:\PlatformIO\libs\system\reEvents\
c:\PlatformIO\libs\system\reI2C\
c:\PlatformIO\libs\system\reNotifier\
c:\PlatformIO\libs\system\reNvs\
c:\PlatformIO\libs\system\reOTA\
c:\PlatformIO\libs\system\reParams\
c:\PlatformIO\libs\system\reScheduler\
c:\PlatformIO\libs\system\reStates\
c:\PlatformIO\libs\system\reSysInfo\
c:\PlatformIO\libs\system\rLog\
c:\PlatformIO\libs\system\rStrings\
c:\PlatformIO\libs\system\rTypes\
c:\PlatformIO\libs\wifi\rePinger\
c:\PlatformIO\libs\wifi\reSNTP\
c:\PlatformIO\libs\wifi\reWiFi\

The paths to them are specified in platformio.ini:

lib_extra_dirs =
    C:\PlatformIO\libs\system
    C:\PlatformIO\libs\peripherals
    C:\PlatformIO\libs\sensors
    C:\PlatformIO\libs\wifi
    C:\PlatformIO\libs\clouds
    C:\PlatformIO\libs

Until some time everything worked. Now, when trying to change something in the project, an error is generated that one random library from the OLD ones that previously worked successfully was not found:

C:/PlatformIO/libs/system/reStates/src/reStates.cpp:26:12: fatal error: reNotifier.h: No such file or directory

********************************************************************
* Looking for reNotifier.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:reNotifier.h"
* Web  > https://registry.platformio.org/search?q=header:reNotifier.h
*
********************************************************************

   #include "reNotifier.h"

Although yesterday everything worked fine in this very place.

In addition, I discovered the following problem: if I disable a particular library using preprocessor conditions, it still compiles. I tested it by messing up some of the code inside it but with the exact same condition, which is guaranteed to result in an error. For example:

#define CONFIG_OPENMON_ENABLE 0
....

#if CONFIG_OPENMON_ENABLE
#include "reOpenMon.h"
#endif // CONFIG_OPENMON_ENABLE

Inside reOpenMon.h the error is framed in

#if !CONFIG_OPENMON_ENABLE
bug();
#endif // !CONFIG_OPENMON_ENABLE

In theory, there should be no compilation errors, since the entire library is excluded from the project. But no! Compiler says bug() not found

A different lib_ldf_mode that evaluates preprocessor macros might help here. Still, PlatformIO sometimes has bugs in regards to this.

Maybe a dependency is not recongized or the project has a local copy of an version? Try adding lib_ldf_mode to resolve this and delte the .pio folder of the project, then build again.

If this does still not work out, please do a Advanced → Verbose Build in the project tasks and post the dependency graph.

1 Like

How about removing lib_extra_dirs and directly declaring local dependency using virtual symbolic links?

lib_deps = 
  symlink://c:/PlatformIO/libs/system/reStates
  symlink://c:/PlatformIO/libs/system/reNotifier

I now have it like this:

lib_ldf_mode = deep+

Thanks, I got the idea, I’ll give it a try…

However, as far as I understand, I will have to describe each included library. Will it compile if I “disable” it programmatically using a preprocessor.

The fact is that I manage the esp32 configuration using a single file (similar to sdkconfig.h, but my own). And periodically turn on or off certain options. For example, now the device sends data to one cloud, and tomorrow I want to disable it and enable another.

The cause of the problem was found.
It turned out that in the folder with the library that refused to compile, there was no library.json file. However, it is strange that before and in his absence everything worked well, and suddenly stopped.

1 Like