Local libraries and include dependencies

Hi, all!

I’m using PlatformIO in Atom for Arduino programming. I get dependencies error when build bellow code. This is my reproduction sample code:


#ifndef MYLIB_H
#define MYLIB_H

#include <Arduino.h>

void fn();



#include <mylib.h>

void fn()


#ifndef MYCLIM_H
#define MYCLIM_H

#include <Arduino.h>
#include <DHT.h>

void fnclim();



#include <myclim.h>

void fnclim()


#include <Arduino.h>
#include <mylib.h>
#include <myclim.h>

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:

The above code is compiled without errors. But, if I remove the line #include <myclim.h> in main.cpp, I get the follow error:

Processing pro16MHzatmega328 (platform: atmelavr; board: pro16MHzatmega328; framework: arduino)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/pro16MHzatmega328.html
PLATFORM: Atmel AVR > Arduino Pro or Pro Mini ATmega328 (5V, 16 MHz)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf

Collected 17 compatible libraries
Scanning dependencies...
Dependency Graph
|-- <mylib>
Compiling .pioenvs/pro16MHzatmega328/src/main.cpp.o
Compiling .pioenvs/pro16MHzatmega328/lib2cc/mylib/myclim.cpp.o
In file included from lib/mylib/myclim.cpp:1:0:
lib/mylib/myclim.h:5:17: fatal error: DHT.h: No such file or directory

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

compilation terminated.
*** [.pioenvs/pro16MHzatmega328/lib2cc/mylib/myclim.cpp.o] Error 1

I’d like to know why is it happens. Some times, I need include myclim.h in main.cpp, but sometimes I don’t. Why is it happens if DHT dependency is ok?

I tried to compile this code in Arduino IDE, and have no error, including or not myclim.h in main.cpp. In this case, DHT.h is always compiled in Arduino IDE, even if myclim.h is not included in main.cpp.

Thank you!

Which DHT library are you using? Adafruits’s? You should always declare dependencies in your lib_deps statement of the platformio.ini.

Seems PlatformIO could detect that if you not include <myclim.h then #include <DHT.h will not be reached, but because it unciditionally compiles all cpp files of the library, it will give you a compiler error. May be usefull to open an issue at GitHub - platformio/platformio-core: A professional collaborative platform for embedded development.

1 Like

Yes, I’m using Adafruits library. That is true, PlatformIO seems DHT may not be reached if not include myclim.h. I tested with Arduino IDE and don’t have error, including or not myclim.h in main code.

See my comment local libraries and include dependencies · Issue #2941 · platformio/platformio-core · GitHub

1 Like