1

I, once again have difficulties including libraries from code files other than my .ino file.

I have several .cpp and .h files in my project to keep it sorted and clean. However one of my header files starting like this:

#ifndef DPLANDEF
#define DPLANDEF
#include <Arduino.h>
#include <EEPROM.h>
#include "syssettings.h"

yields the following errors:

In file included from /var/folders/jl/nv1qvh6n569cxq9xxfd6dx980000gn/T/build4605486877500371361.tmp/dplan.cpp:2:0: /var/folders/jl/nv1qvh6n569cxq9xxfd6dx980000gn/T/build4605486877500371361.tmp/dplan.h:5:20: fatal error: EEPROM.h: No such file or directory #include ^ compilation terminated. Fehler beim Kompilieren.

EEPROM.h should be known to the IDE, because I can find it in the libraries menu, too. If it was a custom library, I might have botched something during installation, but this is a standard library. It should work out of the box. What's the problem here?

2

1 Answer 1

2

The problem here is that it's a header file. The IDE doesn't treat header files like it does INO files - it doesn't parse them for included libraries, etc.

In order for it to work you must also include EEPROM.h in your main INO file so that the IDE knows that you want to include it in the rest of your files.

8
  • Thanks a lot. In the past I fiddled cluelessly around until it finally somehow worked out. After adding all libs to my INO header file, all libraries are detected, but I have a new problem. The IDE somehow managed to circumvent the include guard definition of PinChangeInt.h (custom library, which I tested already successfully). Linker is now complaining about lots of double definitions. Sigh. I guess time to move to a "real" IDE!?
    – Ariser
    Aug 29, 2015 at 22:20
  • @Ariser Include guards only work within the same compilation unit. If you include the file in separate cpp or ino files it will exist multiple times, and any variables or functions defined in there will be conflicting. You should never have functions or variables in headers - put them (once) in cpp or ino files and put extern references to them in the header files. The header files then act like a "sharing" point for the variables and functions in the other cpp and ino files.
    – Majenko
    Aug 29, 2015 at 22:43
  • Sigh. I guess time to move to a "real" IDE!? - you would have that problem anywhere. As Majenko said, .h files are for declarations. To define something it should be done once, in a .c or .cpp file. You won't get double definitions on the class declaration. Your PinChangeInt library should also have a PinChangeInt.cpp file which is compiled once.
    – Nick Gammon
    Aug 29, 2015 at 22:52
  • 2
    @IgorStoppa - yes it is intended for newbies, and you must surely admit that Make is not for the faint-hearted. The process is described in a reply I made. I note that Ariser now says that the library is a mess, which presumably lets the build process of the hook a bit. The IDE can't help it if people put all their functions into .h files.
    – Nick Gammon
    Aug 30, 2015 at 20:34
  • 1
    @NickGammon: the build process is still a mess as it does (black) magic with headers and I consider it as an encouragement to people doing even more evil things with headers. Aug 30, 2015 at 20:39

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.