1

I'm using PlatformIO in Atom for Arduino programming. I get dependencies error when build. 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 it is happen. Some times, I need include myclim.h in main.cpp, but sometimes I don't. Why is it happens if DHT dependency is ok?

Thank you!

  • it depends if the dht library header is first processed in the sketch or in library? – Juraj May 23 at 8:05
  • It looks that when dht library is included in sketch, compiling is ok. But, when dht library is only in mylib, a dependency error occur. The path for dht library is the same. I don't know why builder not find dht library when it is included only in mylib. – Mario J. May 23 at 13:42
  • did you try it in Arduino IDE? – Juraj May 23 at 14:21
  • Yes, I tried, @Juraj . I do not have error, including or not myclim.h in main.cpp. But, I note in Arduino IDE output that DHT.h is always compiled, even if myclim.h is not included in main.cpp. – Mario J. May 31 at 10:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.