Problem with dependencies between local libraries since CLI 5.0

Hello everyone.

Since release of CLI 5.0 (and 5.0.1 has not changed the behavior), I am getting the following errors when building and testing this project I am partaking in.

EDIT: I figured out and fixed a circular dependency problem between libraries in the project, which solved the build issue! The second (testing) issue is still present.
Working solution for the first issue is available in this branch

$ pio run
[…]
Compiling .pio/build/stm32/lib511/debug/debug.o
In file included from lib/hal/circular_buffer.h:19,
from lib/debug/debug.h:19,
from lib/debug/debug.cpp:49:
lib/hal/hal.h:35:10: fatal error: units.h: No such file or directory
[…]
35 | #include “units.h”
| ^~~~~~~~~
compilation terminated.
*** [.pio/build/stm32/lib511/debug/debug.o] Error 1

Note that the exact same project works fine with CLI 4.3.4. Also note that because we are working on safety critical software, we deliberately don’t use external libraries (so it doesn’t risk breaking when an external library auto-updates).

Here are the information I think will be useful, but feel free to ask (or check the github repo) for additional information:

Dependency Graph
|-- core
| |-- hal
| | |-- checksum
| | |-- units
| | |-- debug
| |-- debug
| |-- network_protocol
| | |-- nanopb
| |-- units
| |-- nanopb
| |-- pid
| | |-- units
|-- hal
| |-- checksum
| |-- units
| |-- debug
|-- debug
|-- network_protocol
| |-- nanopb
|-- units
|-- nanopb
|-- pid
| |-- units
|-- checksum

The (somewhat simplified) project tree goes like this:

common
    generated_libs
        network_protocol
    libs
        checksum
        units
    third_party
        nanopb
controller //this is the platformio project
    lib
        core
        debug
        hal
        pid
    platformio
    src
    platformio.ini

platformio.ini specifies
lib_dir = lib
lib_ldf_mode = deep+
lib_extra_dirs =
…/common/libs
…/common/generated_libs
…/common/third_party

BTW, when I replace
#include “units.h”
in hal.h with
#include “…/…/…/common/libs/units/units.h”
the project builds properly, which raises the question: how come #include “network_protocol.h” and #include “pb.h” (which is in third_party/nanopb) work if #include “units.h” fails?

Now the second problem, which also started with CLI 5.0: when working on unit tests for this project with googletest library, unit tests of lib/core that require other libraries (e.g lib/debug) yield the following linker error:

Building…
.pio/build/native/lib61e/libcore.a(blower_fsm.o) : In function « DebugVarBase::DebugVarBase(VarType, char const*, char const*, char const*) » :
/data/RespiraWorks/VentilatorSoftware/software/controller/lib/debug/vars.h:47 : undefined reference to « DebugVarBase::var_count »
[… plenty of similar errors]
collect2: error: ld returned 1 exit status
*** [.pio/build/native/program] Error 1

Once again, I have an unsatisfying solution, which is to get rid of our current architecture and put all the files in lib/core.
Any help is immensely appreciated!

Please provide an archive of a simple project to reproduce this issue.

Here it is with a much simpler structure.

confirmed OK with platformio 4.3.4 :

$ pio test -e native


Obsolete PIO Core v4.3.4 is used (previous was 5.0.1)
Please remove multiple PIO Cores from a system:
Redirecting...


Verbose mode can be enabled via -v, --verbose option
Collected 1 items

Processing controller in native environment

Building…
Testing…
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from ControllerTest
[ RUN ] ControllerTest.BreathId
[ OK ] ControllerTest.BreathId (0 ms)
[----------] 1 test from ControllerTest (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 1 test.
=============================================================================== [PASSED] Took 6.40 seconds ===============================================================================

Test Environment Status Duration


controller nucleo_l452re IGNORED
controller native PASSED 00:00:06.403

and failed with platformio 5.0.1

$ pio test -e native
Verbose mode can be enabled via -v, --verbose option
Collected 1 items

Processing controller in native environment

Building…
.pio/build/native/lib72e/libcore.a(controller.o) : Dans la fonction « Controller::Run(int) » :
/data/RespiraWorks/pio_issue_minimal/pio_dep_issue/lib/core/controller.cpp:21 : référence indéfinie vers « PID::Compute(int, float, float) »
collect2: error: ld returned 1 exit status
*** [.pio/build/native/program] Error 1
=============================================================================== [FAILED] Took 5.84 seconds ===============================================================================

Test Environment Status Duration


controller nucleo_l452re IGNORED
controller native FAILED 00:00:05.840

Just tested this again after noticing CLI 5.0.2 is out, it looks like this issue is now solved.
(Looks linked to Native environment linker problems after upgrading to 5.0.1 · Issue #3669 · platformio/platformio-core · GitHub )

Thanks!