6

I have following code:

MyApp.ino:

#include "DfRobotLcdShield.h"

void setup() {
}

void loop() {
}

DfRobotLcdShield.h:

#include <LiquidCrystal.h>

When I try to compile, I'm getting the error:

In file included from MyApp.ino:1:0:
c:\temp\build5856181074637812172.tmp\DfRobotLcdShield.h:4:27: fatal error: LiquidCrystal.h: No such file or directory
 #include <LiquidCrystal.h>
                           ^
compilation terminated.
Error compiling.

When I add

#include <LiquidCrystal.h>

directly to the .ino file, it works. I'm using the latest Arduino-IDE 1.6.3.

1
  • 1
    It sounds like you're outgrowing the limitations of the Arduino IDE. I'm not offering this as an answer because changing IDEs is not a quick fix, but consider upgrading to more capable tools in the not-too-distant future.
    – JRobert
    Apr 6, 2015 at 18:08

2 Answers 2

4

This seems to be a general problem of the Arduino IDE: It only recognizes libraries that are included in the (primary) .ino file.

If you look at the invocation of the compiler, the path to any given library is only added if this library's header file is included in the .ino file.

I tested this with the EEPROM library. If this library is included in the .ino file, the compiler is called with

avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/eightanaloginputs -I/usr/share/arduino/libraries/EEPROM /tmp/build2678545434708654378.tmp/test.cpp -o/tmp/build2678545434708654378.tmp/test.cpp.o 

where the important part is the -I/usr/share/arduino/libraries/EEPROM.

If I now remove #include <EEPROM.h> (but still have it in another header file which in turn is included in the .ino as in your case), the compiler call changes to

avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/eightanaloginputs /tmp/build2678545434708654378.tmp/test.cpp -o/tmp/build2678545434708654378.tmp/test.cpp.o

where now the include path to the library is missing.

TL;DR

If you need to use a library, just (also) add an include to the .ino file. It doesn't cost you anything and will solve your problem ;)


#include <file> vs. #include "file"

From the gcc documentation:

  • #include <file> is used for system header files. It searches for a file named file in a standard list of system directories. [...]
  • #include "file" is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. [...]
-1

Try #include "LiquidCrystal.h"

Or where is the library located? Be sure the include specifies the location.

You might have to add the library location to your environment variables.

5
  • LiquidCrystal.h is a system library and hence, according to my limited C knowledge, has to be included with < >.
    – Thomas S.
    Apr 5, 2015 at 4:49
  • Did you add it through "sketch -> include library -> LiquidCrystal.h"?
    – Paul
    Apr 5, 2015 at 8:25
  • I've tried that, too, without any difference.
    – Thomas S.
    Apr 5, 2015 at 9:27
  • Can you verify that this file is in your libraries folder? You could try to put it in your project folder, so that the linker doesn't have to look that far
    – Paul
    Apr 5, 2015 at 10:10
  • Yes, it is there - please read my 2nd last sentence in the question.
    – Thomas S.
    Apr 5, 2015 at 17:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.