Library compiles when in lib folder, but not when in lib_deps

Here is my platformio.ini:

[env:lolin_d32]
platform = https://github.com/tasmota/platform-espressif32/releases/download/2024.07.11/platform-espressif32.zip
board = lolin_d32
framework = arduino
lib_deps = askuric/Simple FOC

And my main.cpp:

#include <Arduino.h>
void setup() {}
void loop() {}

Compilation of the “askuric/Simple FOC” library hangs at some point:

Processing lolin_d32 (platform: https://github.com/tasmota/platform-espressif32/releases/download/2024.07.11/platform-espressif32.zip; board: lolin_d32; framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/espressif32/lolin_d32.html
PLATFORM: Espressif 32 (2024.7.11) > WEMOS LOLIN D32
HARDWARE: ESP32 240MHz, 320KB RAM, 4MB Flash
DEBUG: Current (cmsis-dap) External (cmsis-dap, esp-bridge, 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.0.2+sha.9100566 
 - tool-esptoolpy @ 4.7.4 
 - tool-mklittlefs @ 3.2.0 
 - tool-riscv32-esp-elf-gdb @ 11.2.0+20220823 
 - tool-xtensa-esp-elf-gdb @ 11.2.0+20230208 
 - toolchain-xtensa-esp32 @ 12.2.0+20230208
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 26 compatible libraries
Scanning dependencies...
Dependency Graph
|-- Simple FOC @ 2.3.4
Building in release mode
Compiling .pio\build\lolin_d32\libf27\Simple FOC\current_sense\hardware_specific\teensy\teensy4_mcu.cpp.o
Compiling .pio\build\lolin_d32\libf27\Simple FOC\drivers\hardware_specific\atmega\atmega2560_mcu.cpp.o
Compiling .pio\build\lolin_d32\libf27\Simple FOC\drivers\hardware_specific\atmega\atmega328_mcu.cpp.o
Compiling .pio\build\lolin_d32\libf27\Simple FOC\drivers\hardware_specific\atmega\atmega32u4_mcu.cpp.o
Compiling .pio\build\lolin_d32\libf27\Simple FOC\drivers\hardware_specific\due_mcu.cpp.o
Compiling .pio\build\lolin_d32\libf27\Simple FOC\drivers\hardware_specific\esp32\esp32_driver_mcpwm.cpp.o
Compiling .pio\build\lolin_d32\libf27\Simple FOC\drivers\hardware_specific\esp32\esp32_ledc_mcu.cpp.o
Compiling .pio\build\lolin_d32\libf27\Simple FOC\drivers\hardware_specific\esp32\esp32_mcpwm_mcu.cpp.o
In file included from .pio/libdeps/lolin_d32/Simple FOC/src/current_sense/hardware_specific/teensy/../../../drivers/hardware_specific/teensy/teensy_mcu.h:4,
                 from .pio/libdeps/lolin_d32/Simple FOC/src/current_sense/hardware_specific/teensy/../../../drivers/hardware_specific/teensy/teensy4_mcu.h:4,
                 from .pio/libdeps/lolin_d32/Simple FOC/src/current_sense/hardware_specific/teensy/teensy4_mcu.cpp:2:
.pio/libdeps/lolin_d32/Simple FOC/src/current_sense/hardware_specific/teensy/../../../drivers/hardware_specific/teensy/../../hardware_api.h:6:10: fatal error: ../communication/SimpleFOCDebug.h: No such file or directory
    6 | #include "../communication/SimpleFOCDebug.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

This is odd, because …/communication/SimpleFOCDebug.h is really there. There’s also a random factor, as sometimes the same error occurs with another include file. In fact, at one point, any attempt to include a file with a relative path seems to trigger an error.

If I remove the library from lib_deps and copy it the lib folder, it compiles without a glitch.

I’ve done a Full Clean, deleted the .pio folder, uninstalled/reinstalled PlatformIO, but it didn’t solve the problem.

Has anyone experienced this?

This also occurs with other libraries and is related to the Library Dependency Finder (LDF). The error only occurs if the library is specified in the lib_deps but is not included.
Which actually makes no sense, because if you specify a library in the lib_deps, you usually want to use it and include it into your source files.

There are 3 solutions:

  1. Include the library into your source files: #include <SimpleFOC.h>
  2. Set lib_ldf_mode = deep (or deep+) in platformio.ini
  3. Remove the library from the lib_deps (if you do not want to use it)

See Library Dependency Finder (LDF) — PlatformIO latest documentation

1 Like

Thanks a lot @sivar2311 , but unfortunately I had already tried what you suggest and it didn’t work: including <SimpleFOC.h> in main.cpp and changing lib_ldf_mode doesn’t make any difference.

I found a workaround: in order to prevent the error from happening, it’s enough to replace relative include paths by absolute include paths in the library.

In hardware_api.h, replace:

#include "../communication/SimpleFOCDebug.h"
#include "../common/base_classes/BLDCDriver.h"

by:

#include "communication/SimpleFOCDebug.h"
#include "common/base_classes/BLDCDriver.h"

So it seems there’s really something wrong with relative paths.

What is “hardware_api.h” and where does it come from? Your example was an empty “main.cpp”:

#include <Arduino.h>
void setup() {}
void loop() {}

This issue is due to include file paths being too long. I don’t know if it’s a problem in Windows, in PlatformIO, or in a third-party tool used by PlatformIO. The issue is being discussed here.

A workaround is to move the project folder closer to the root of the drive, so that file paths are shorter.