I’m running into an issue with PIO and the way I have libraries set up (all inside the lib/
folder, no external libs). The approach I’m using may not be common, but it has been working very well so far:
-
strict mode, i.e. in
[env]
, I havelib_compat_mode = strict
-
there’s a library in
lib/hall-stm32/
which only works on STM32 -
it includes a file
lib/hall-stm32/library.json
containing a single line:{ "platforms": "ststm32" }
-
there’s another library in
lib/hall-native/
which only works for native builds -
it too includes a file
lib/hall-native/library.json
with:{ "platforms": "native" }
-
both libraries have a header file called
hall.h
, with different content, as well as some other source files
So the idea is that when I include hall.h
in main, or in another library, it will find just the version which matches the current build target. For main
, this does indeed work well, but my impression is that when used in this way from another library (“lib/boss/” in this case, which is platform-independent and contains no library.json
file), then things get mixed up. Here is the build output I see:
$ pio run -c ../../platformio.ini
Processing native (platform: native)
-------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ strict
Found 2 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <boss>
| |-- <hall-native>
|-- <hall-native>
Building in release mode
Compiling .pio/build/native/src/lib/boss/boss.o
Compiling .pio/build/native/src/lib/hall-stm32/hall.o
Compiling .pio/build/native/src/lib/hall-stm32/stm32l4.o
Compiling .pio/build/native/src/main-blink.o
Compiling .pio/build/native/src/main-native.o
Compiling .pio/build/native/src/main-uart.o
Archiving .pio/build/native/lib5ae/libhall-native.a
In file included from lib/hall-stm32/hall.cpp:1:
lib/hall-stm32/hall.h:45:22: error: cast from pointer to smaller type 'uint32_t' (aka 'unsigned int') loses information
auto a = (uint32_t) &addr;
^~~~~~~~~~~~~~~~
lib/hall-stm32/hall.h:40:15: error: cannot deduce return type 'auto &' for function with no return statements
auto& at (int b) {
^
lib/hall-stm32/hall.h:52:15: error: cannot deduce return type 'auto &' for function with no return statements
auto& operator[] (int b) { return at(b); }
^
lib/hall-stm32/hall.h:99:56: error: use of undeclared identifier 'GPIO'
auto gpio32 (int off) const -> IOWord { return GPIO(0x400*_port+off); }
[etc...]
Note the “In file included from lib/hall-stm32/hall.cpp:1:” message. Somehow, a file from a library which shouldn’t be included in the native build has found its way in …
Could this be caused by the fact that main
is using a generic boss
which is in turn using a platform-specific hall
?
For anyone interested in trying this out, these steps should suffice:
git clone https://github.com/jeelabs/monty.git
cd monty
git switch jcw
cd examples/hall/
pio run -c ../../platformio.ini -e native
I just tried this, I don’t think there are any outside dependencies.