1

I am trying to create a new library that uses another existing library.

The original library declares a way to create an object called Multiserial that can be created in the main file and the program is correctly compiled.

However, when I include this library in a second one and I try to build the program, then the IDE returns an error that says:

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:27:0, from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26, from MultiSerial.h:17, from maqMODBUSmst.h:5, from maqMODBUSmst.c:1: C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Printable.h:25:1: error: unknown type name 'class' class Print;

Even if the library only contains the include of the first one.

  • 1
    I am absolutely stupid. The fail was that ai was trying to use classes in a .c instead creating a .cpp – Zero point Nov 20 '15 at 10:07
2

Nested includes lead to these convoluted error messages and are in general, a PITA for the next reader to follow & understand. It is better practice for the dependent library to test, at compile time, for the existence of its required libraries and for each one found missing, issue:

#error DepLibe.h: Missing required include file ReqLibe.h

Most .h files guard against multiple-inclusion by

#ifndef _REQLIBE_H_
#define _REQLIBE_H_
// library definitions here

or some variant of it. DepLibe.h can test for these guard symbols. DepLibe.h should document the dependencies in prominent comments.

Your Answer

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

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