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:
/lib/mylib/mylib.h
#ifndef MYLIB_H
#define MYLIB_H
#include <Arduino.h>
void fn();
#endif
/lib/mylib/mylib.cpp
#include <mylib.h>
void fn()
{
Serial.println("fn1");
}
/lib/mylib/myclim.h
#ifndef MYCLIM_H
#define MYCLIM_H
#include <Arduino.h>
#include <DHT.h>
void fnclim();
#endif
/lib/mylib/myclim.cpp
#include <myclim.h>
void fnclim()
{
Serial.println("fnclim");
}
/src/main.cpp
#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)
HARDWARE: ATMEGA328P 16MHz 2KB RAM (30KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
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!