Library not finding platform libraries during build?

I have a project with the following file structure:

led-test
│   platformio.ini
│
├───lib
│   │   readme.txt
│   │
│   └───ht16k33
│       └───src
│               ht16k33.cpp
│               ht16k33.h
│
└───src
        main.cpp

And the following files:

main.cpp

#include <Arduino.h>
#include <ht16k33.h>

...

ht16k33.cpp

#include <Wire.h>

...

When I build it fails with the following error:

.pioenvs\teensy31\ht16k33\ht16k33.cpp:2:18: fatal error: Wire.h: No such file or directory
#include <Wire.h>
^
compilation terminated.

This happens even though the code hinting/completion system doesn’t complain about it. When I change main.cpp to include <Wire.h>, like this:

#include <Arduino.h>
#include <Wire.h>
#include <ht16k33.h>

...

It succeeds just fine. I think this is simply the build not including platform libraries (e.g. teensy’s Wire.h). Is there anyway to fix the build to include platform libraries while building libraries in the lib tree? If I am misunderstanding the problem can you enlighten me?


This is on Windows, IDE 1.3.6, CLI 2.11.1. For reference, my platform.ini file:

[env:teensy31]
platform = teensy
framework = arduino
board = teensy31

Okay, after some digging, it looks like this is a known issue, that may be fixed in the 3.0 release. (See Return of #48 - Problem with #include <SPI.h> · Issue #702 · platformio/platformio-core · GitHub for an example.)

Solution 1

Add #include <Wire.h> to one of the project file.

Solution 2

See lib_deps.

[env:teensy31]
platform = teensy
framework = arduino
board = teensy31
lib_deps = Wire

I’ve been using PlatformIO v3 and had a similar issue with library 12, Adafruit_ST7735_ID12.

(pio3dev) $ platformio run --verbose
[Sun Jul 31 10:08:09 2016] Processing teensy31 (platform: teensy, lib_install: 12, 13, 129, 291, 1106, 416, board: teensy31, framework: arduino)
-------------------------------------------------------------------------------------------------------------------------------------------------------------------
Framework incompatible library /Users/home/.platformio/lib/Terminal_ID249
Collected 31 compatible libraries
Looking for dependencies...
Library Dependency Map
|-- <Bounce2> v2.1 (/Users/home/.platformio/lib/Bounce2_ID1106)
|-- <TinyGPS> (/Users/home/.platformio/lib/TinyGPS_ID416)
|-- <RKW_Led> v0.1.0 (/Users/home/.platformio/lib/RKW_Led)
|-- <Encoder> (/Users/home/.platformio/lib/Encoder_ID129)
|-- <ADC> (/Users/home/.platformio/lib/ADC)
|-- <Display> (/Users/home/arduino/digihead/lib/Display)
|   |-- <SPI> v1.0 (/Users/home/.platformio/packages/framework-arduinoteensy/libraries/SPI)
|   |-- <ADC> (/Users/home/.platformio/lib/ADC)
|   |-- <Adafruit-GFX> (/Users/home/.platformio/lib/Adafruit_GFX_ID13)
|   |-- <Adafruit-ST7735> (/Users/home/.platformio/lib/Adafruit_ST7735_ID12)
|   |   |-- <Adafruit-GFX> (/Users/home/.platformio/lib/Adafruit_GFX_ID13)
|-- <MTS> (/Users/home/arduino/digihead/lib/MTS)
arm-none-eabi-g++ -o .pioenvs/teensy31/lib/Adafruit-ST7735/Adafruit_ST7735.o -c -fno-exceptions -std=gnu++0x -felide-constructors -fno-rtti -g -Os -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -DPLATFORMIO=030000 -D__MK20DX256__ -DUSB_SERIAL -DARDUINO=10600 -DTEENSYDUINO=128 -I.pioenvs/teensy31/FrameworkArduino -I/Users/home/.platformio/packages/framework-arduinoteensy/cores/teensy3 -I.pioenvs/teensy31/lib/Adafruit-GFX -I/Users/home/.platformio/lib/Adafruit_GFX_ID13 -I.pioenvs/teensy31/lib/Adafruit-ST7735 -I/Users/home/.platformio/lib/Adafruit_ST7735_ID12 /Users/home/.platformio/lib/Adafruit_ST7735_ID12/Adafruit_ST7735.cpp
arm-none-eabi-ar rcs .pioenvs/teensy31/lib/libDisplay.a .pioenvs/teensy31/lib/Display/Display.o
arm-none-eabi-ranlib .pioenvs/teensy31/lib/libDisplay.a
/Users/home/.platformio/lib/Adafruit_ST7735_ID12/Adafruit_ST7735.cpp:28:17: fatal error: SPI.h: No such file or directory
#include <SPI.h>
^
compilation terminated.
scons: *** [.pioenvs/teensy31/lib/Adafruit-ST7735/Adafruit_ST7735.o] Error 1
==================================================================== [ERROR] Took 0.74 seconds ====================================================================

Build fails because it can’t find SPI.h. Other files in my project include SPI.h and compile correctly.

So, after reviewing the v3 library docs, I decided to try adding SPI as a dependency to that library, and now it works correctly…

  "dependencies":[
    {
      "name": "Adafruit-GFX",
      "frameworks": "arduino"
    },
    {
      "name": "SPI",
      "frameworks": "arduino"
    }
  ],

Relevant changes in output are:

|   |-- <Adafruit-ST7735> (/Users/robwills/.platformio/lib/Adafruit_ST7735_ID12)
|   |   |-- <Adafruit-GFX> (/Users/robwills/.platformio/lib/Adafruit_GFX_ID13)
|   |   |-- <SPI> v1.0 (/Users/robwills/.platformio/packages/framework-arduinoteensy/libraries/SPI)

and

arm-none-eabi-g++ -o .pioenvs/teensy31/lib/Adafruit-ST7735/Adafruit_ST7735.o -c -fno-exceptions -std=gnu++0x -felide-constructors -fno-rtti -g -Os -Wall -ffunction-sections -fdata-sections -mthumb -mcpu=cortex-m4 -nostdlib -fsingle-precision-constant -DF_CPU=72000000L -DLAYOUT_US_ENGLISH -DPLATFORMIO=030000 -D__MK20DX256__ -DUSB_SERIAL -DARDUINO=10600 -DTEENSYDUINO=128 -I.pioenvs/teensy31/FrameworkArduino -I/Users/robwills/.platformio/packages/framework-arduinoteensy/cores/teensy3 -I.pioenvs/teensy31/lib/Adafruit-GFX -I/Users/robwills/.platformio/lib/Adafruit_GFX_ID13 -I.pioenvs/teensy31/lib/SPI -I/Users/robwills/.platformio/packages/framework-arduinoteensy/libraries/SPI -I.pioenvs/teensy31/lib/Adafruit-ST7735 -I/Users/robwills/.platformio/lib/Adafruit_ST7735_ID12 /Users/robwills/.platformio/lib/Adafruit_ST7735_ID12/Adafruit_ST7735.cpp`

While this is working for me right now, was this the right “fix”, or is there something else I should have done?

Just upgrade to 3.0.0.dev14 and remove spi from manifest. I fixed it yesterday.

See updated docs Redirecting...

Yep, all good with dev15!

Thanks a lot for the report!

How is PlatformIO 3.0? :slight_smile:

Really good. My main productivity increase is with the CLion IDE integration.

The next thing on my wish list is Google Test integration :grin: I want to write unit tests for my serial packet decoders that run in the IDE with the debugger active.

That is great! :wink: :sun_with_face:

Could you explain in details what do you need? Do you mean this issue?

P.S: Please update to PlatformIO 3.0.0.dev19. I hope that it will be the latest development in “feature” branch. I’m going to merge it to develop branch next week and release first alpha for internal testers. I’ll report here.

New docs:

I’ve got a serial protocol that I’m decoding with a class. My serial handler feeds bytes to the decoder and it handles parsing into a data structure based on the packet type etc.

I would very much like to write a test case for each part of the protocol, and feed it particular byte sequences to verify what the internal variables have in them throughout the decode. I don’t know of any way to set breakpoints and collect debug data from the arduino-teensy application while it’s executing on the device.

If I implement another part of the serial protocol and get it wrong, I can’t debug that mistake, except to litter the class with Serial.println() statements, and see what gets sprayed back on the terminal!

It seems relatively common in the embedded software world to use Google Test framework and CMake to create unit tests that execute on the build host (optionally in your IDE with breakpoints set!). This would let me step through my code, watching the variables and quickly find my mistakes :slight_smile:

Please upgrade to PlatformIO 3.0.0a1 :blush: . It’s now merged to develop branch.

Please platformio upgrade to 3.0.0a4 where is implemented Local Unit Testing. See example

Updated docs: http://docs.platformio.org/en/latest/unit_testing.html

I know this thread is as dead as a thread can be, but nevertheless: As I had a similar problem with the missing “SPI.h”, I tried to apply @ohhrob 's solution (adding the dependency in library.json), and … tada, it’s working now! No more complaints while compiling. Thanks!

As I just ended up here because SPI.H still can’t be found, there is now a much simpler solution. Just add a
lib_ldf_mode = deep
statement to your platformio.ini file for the appropriate build environment.

1 Like

A few years later I had to add:

lib_ldf_mode = deep

to compile the basic SHTC3 I2C humidity sensor example.

It would be nice to add something like:

Warning:
The code may not compile without adding lib_ldf_mode = deep in platformio.ini

to the installation instructions to avoid people spending time on searching old posts or even opening new threads.

BTW, is adding lib_ldf_mode = deep after all these years still the best solution for the SPI.h not found problem?

#include <SPI.h> at the top of the firmware code or add SPI to lib_deps in the platformio.ini.