PlatformIO Community

Build fails after adding library

I am not able to add any library to my project. Each time I do the build fails (see below). When I add the library using the registry I select Add file to project. The IDE tells me the project was added successfully but this cannot be the case.

> Executing task: platformio run --environment nanoatmega328new <

Processing nanoatmega328new (platform: atmelavr; board: nanoatmega328new; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (2.1.0) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES: 
 - framework-arduino-avr 5.0.0 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 24 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <MCP4725> 0.3.0
|-- <Adafruit MCP4725> 2.0.0
Building in release mode
Compiling .pio/build/nanoatmega328new/src/main.cpp.o
Compiling .pio/build/nanoatmega328new/lib788/MCP4725/MCP4725.cpp.o
Compiling .pio/build/nanoatmega328new/lib15a/Adafruit MCP4725/Adafruit_MCP4725.cpp.o
Archiving .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/CDC.cpp.o
Indexing .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial.cpp.o
In file included from .pio/libdeps/nanoatmega328new/Adafruit MCP4725/Adafruit_MCP4725.cpp:20:0:
.pio/libdeps/nanoatmega328new/Adafruit MCP4725/Adafruit_MCP4725.h:10:37: fatal error: Adafruit_BusIO_Register.h: No such file or directory

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

In file included from .pio/libdeps/nanoatmega328new/MCP4725/MCP4725.cpp:28:0:
.pio/libdeps/nanoatmega328new/MCP4725/MCP4725.h:12:18: fatal error: Wire.h: No such file or directory

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

compilation terminated.
compilation terminated.
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial0.cpp.o
*** [.pio/build/nanoatmega328new/lib788/MCP4725/MCP4725.cpp.o] Error 1
*** [.pio/build/nanoatmega328new/lib15a/Adafruit MCP4725/Adafruit_MCP4725.cpp.o] Error 1
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial1.cpp.o
============================================================================ [FAILED] Took 0.99 seconds ============================================================================
The terminal process "platformio 'run', '--environment', 'nanoatmega328new'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

> Executing task: platformio run --environment nanoatmega328new <

Processing nanoatmega328new (platform: atmelavr; board: nanoatmega328new; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (2.1.0) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES: 
 - framework-arduino-avr 5.0.0 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 23 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <MCP4725> 0.3.0
|-- <Adafruit MCP4725> 2.0.0
Building in release mode
Compiling .pio/build/nanoatmega328new/src/main.cpp.o
Compiling .pio/build/nanoatmega328new/lib788/MCP4725/MCP4725.cpp.o
Compiling .pio/build/nanoatmega328new/lib15a/Adafruit MCP4725/Adafruit_MCP4725.cpp.o
Archiving .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/CDC.cpp.o
Indexing .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial.cpp.o
In file included from .pio/libdeps/nanoatmega328new/Adafruit MCP4725/Adafruit_MCP4725.cpp:20:0:
.pio/libdeps/nanoatmega328new/Adafruit MCP4725/Adafruit_MCP4725.h:10:37: fatal error: Adafruit_BusIO_Register.h: No such file or directory

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

compilation terminated.
In file included from .pio/libdeps/nanoatmega328new/MCP4725/MCP4725.cpp:28:0:
.pio/libdeps/nanoatmega328new/MCP4725/MCP4725.h:12:18: fatal error: Wire.h: No such file or directory

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

compilation terminated.
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial0.cpp.o
*** [.pio/build/nanoatmega328new/lib15a/Adafruit MCP4725/Adafruit_MCP4725.cpp.o] Error 1
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial1.cpp.o
*** [.pio/build/nanoatmega328new/lib788/MCP4725/MCP4725.cpp.o] Error 1
============================================================================ [FAILED] Took 1.05 seconds ============================================================================
The terminal process "platformio 'run', '--environment', 'nanoatmega328new'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

> Executing task: platformio run --environment nanoatmega328new <

Processing nanoatmega328new (platform: atmelavr; board: nanoatmega328new; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (2.1.0) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES: 
 - framework-arduino-avr 5.0.0 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 24 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Nova Fitness Sds dust sensors library> 1.5.0
Building in release mode
Compiling .pio/build/nanoatmega328new/src/main.cpp.o
Compiling .pio/build/nanoatmega328new/lib503/Nova Fitness Sds dust sensors library/SdsDustSensor.cpp.o
Compiling .pio/build/nanoatmega328new/lib503/Nova Fitness Sds dust sensors library/SdsDustSensorResults.cpp.o
Archiving .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/CDC.cpp.o
Indexing .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial0.cpp.o
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial1.cpp.o
In file included from .pio/libdeps/nanoatmega328new/Nova Fitness Sds dust sensors library/src/SdsDustSensor.h:30:0,
                 from .pio/libdeps/nanoatmega328new/Nova Fitness Sds dust sensors library/src/SdsDustSensor.cpp:1:
.pio/libdeps/nanoatmega328new/Nova Fitness Sds dust sensors library/src/SdsDustSensorResults.h:6:28: fatal error: SoftwareSerial.h: No such file or directory

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

In file included from .pio/libdeps/nanoatmega328new/Nova Fitness Sds dust sensors library/src/SdsDustSensorResults.cpp:1:0:
.pio/libdeps/nanoatmega328new/Nova Fitness Sds dust sensors library/src/SdsDustSensorResults.h:6:28: fatal error: SoftwareSerial.h: No such file or directory

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

compilation terminated.
compilation terminated.
*** [.pio/build/nanoatmega328new/lib503/Nova Fitness Sds dust sensors library/SdsDustSensorResults.cpp.o] Error 1
*** [.pio/build/nanoatmega328new/lib503/Nova Fitness Sds dust sensors library/SdsDustSensor.cpp.o] Error 1
============================================================================ [FAILED] Took 1.26 seconds ============================================================================
The terminal process "platformio 'run', '--environment', 'nanoatmega328new'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

> Executing task: platformio run --environment nanoatmega328new <

Processing nanoatmega328new (platform: atmelavr; board: nanoatmega328new; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (2.1.0) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES: 
 - framework-arduino-avr 5.0.0 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 24 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit MCP4725> 2.0.0
Building in release mode
Compiling .pio/build/nanoatmega328new/src/main.cpp.o
Compiling .pio/build/nanoatmega328new/lib15a/Adafruit MCP4725/Adafruit_MCP4725.cpp.o
Archiving .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/CDC.cpp.o
In file included from .pio/libdeps/nanoatmega328new/Adafruit MCP4725/Adafruit_MCP4725.cpp:20:0:
.pio/libdeps/nanoatmega328new/Adafruit MCP4725/Adafruit_MCP4725.h:10:37: fatal error: Adafruit_BusIO_Register.h: No such file or directory

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

compilation terminated.
Indexing .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial0.cpp.o
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial1.cpp.o
*** [.pio/build/nanoatmega328new/lib15a/Adafruit MCP4725/Adafruit_MCP4725.cpp.o] Error 1
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial2.cpp.o
============================================================================ [FAILED] Took 0.96 seconds ============================================================================
The terminal process "platformio 'run', '--environment', 'nanoatmega328new'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

> Executing task: platformio run --environment nanoatmega328new <

Processing nanoatmega328new (platform: atmelavr; board: nanoatmega328new; framework: arduino)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328new.html
PLATFORM: Atmel AVR (2.1.0) > Arduino Nano ATmega328 (New Bootloader)
HARDWARE: ATMEGA328P 16MHz, 2KB RAM, 30KB Flash
DEBUG: Current (simavr) On-board (simavr)
PACKAGES: 
 - framework-arduino-avr 5.0.0 
 - toolchain-atmelavr 1.50400.190710 (5.4.0)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 24 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <Adafruit MCP4725> 2.0.0
Building in release mode
Compiling .pio/build/nanoatmega328new/src/main.cpp.o
Compiling .pio/build/nanoatmega328new/lib15a/Adafruit MCP4725/Adafruit_MCP4725.cpp.o
Archiving .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/CDC.cpp.o
In file included from .pio/libdeps/nanoatmega328new/Adafruit MCP4725/Adafruit_MCP4725.cpp:20:0:
.pio/libdeps/nanoatmega328new/Adafruit MCP4725/Adafruit_MCP4725.h:10:37: fatal error: Adafruit_BusIO_Register.h: No such file or directory

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

compilation terminated.
Indexing .pio/build/nanoatmega328new/libFrameworkArduinoVariant.a
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial.cpp.o
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial0.cpp.o
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial1.cpp.o
*** [.pio/build/nanoatmega328new/lib15a/Adafruit MCP4725/Adafruit_MCP4725.cpp.o] Error 1
Compiling .pio/build/nanoatmega328new/FrameworkArduino/HardwareSerial2.cpp.o
============================================================================ [FAILED] Took 0.99 seconds ============================================================================
The terminal process "platformio 'run', '--environment', 'nanoatmega328new'" terminated with exit code: 1.

Terminal will be reused by tasks, press any key to close it.

The platform.ini file

; PlatformIO Project Configuration File

;

; Build options: build flags, source filter

; Upload options: custom upload port, speed and extra flags

; Library options: dependencies, extra library storages

; Advanced options: extra scripting

;

; Please visit documentation for the other options and examples

; https://docs.platformio.org/page/projectconf.html

[env:nanoatmega328new]

platform = atmelavr

board = nanoatmega328new

framework = arduino

lib_deps =

adafruit/Adafruit MCP4725@^2.0.0

You need to at least do a #include <libraryheader.h> in your main code, otherwise PlatformIO’s library dependency finder (LDF) will not resolve the sub-dependencies of the library. In your case, probably #include <Adafruit_MCP4725.h>.

Adding <libraryheader.h> to the source won’t compile. Instead, I tweaked the ini file by adding the extra line lib_ldf_mode = deep. Shallow linking is default in the ini file. Setting it to deep addresses the issue. But there is still an outstanding issue that the library files aren’t added to the project space under the /lib directory

This is wanted. If the platformio.ini can contain the library description to get, the actual files don’t need to be in the lib/ folder where they might be commited and take up space, instead they’re in the temporary folder .pio\libdeps which is not commited. This is arbitrarily changeable via docs.