I have problem with #define and #include directives.
Lets suppose we have a library named testlib1 with header file#define DEF1 1in it, that has only few lines of code
#ifndef DEF1
#error def1 not defined!
#endif
Then just open new empty Arduino project and add #include directive for our test library
#include <testlib1.h>
Now try to comile the project. you'll get error message
#error def1 not defined!
What we missed is definition of DEF1, so we add a definition and now we have ino file with begining
#define DEF1 1
#include <testlib1.h>
We defined DEF1 before #include, so preprocessor undrstands it correctly and complise code without error message.
Ok, seems everything works great, but we need library to declare a class, so we add a class file. But to understand a problem a created another library testlib2 with class definition. There is hader file "testlib2.h"
#ifndef DEF1
#error def1 not defined!
#endif
class testlib2
{
public:
testlib2();
};
and class file "testlib2.cpp"
#include <testlib2.h>
testlib2::testlib2()
{
//any code here
int a=0;
}
and ino file with begining
#define DEF1 1
#include <testlib1.h>
#include <testlib2.h>
Now in both libraries testlib1 and testlib2 uses same definition DEF1. after compilinig testlib2 gives error message
...\libraries\testlib2/testlib2.h:2:2: error: #error def1 not defined!
Why testlib2 can't see the definition DEF1 that is seen in testlib1?
I discovered just one thing, arduino creates temprorary folder build.tmp and copyes there all the files that compiler need to compile sketch (including libraries), for testlib1 it doesn't copies header file, but for testlib2 it copies testlib2.cpp. I suppose somehow that affects definition directives.
Any ideas?