Hello together, i am new here and have a problem using header files.
In my main sketch i included a library named u8g2lib.h
This lib was installed properly.
Also in the main.cpp i activated this lib and i can access to the dedicated commands.
e.g.: u8g2.sendBuffer();
Now i wrote a new file named OLED.h and placed it into the “include” and “lib” folder.
Now an can’t access to my command u8g2… from the src folder.
In src-folder is placed #include <OLED.H>.
Simple functions are reachable from the main sketch to the OLED.h folder without any problems.
Only keywords defined in outer (foreign) libraries are unreachable.
Can anyone please give a tip? Thank you!
Placing the OLED.h
in two folders is not needed. It’s enough to have it in include/
.
Don’t place single files in lib/
. To create a library, you are expected to create a new directory inside lib/
, and then place source and header files inside there. See README. You do not need to use lib/
to share variables across files in your project.
To share variables, such as u8g2
, in between cpp files by the means of a header files, see https://stackoverflow.com/a/10422050/5296568. extern <type> <name>
in the header and <type> <name>
in one cpp file is the key thing there.
For a more directed answer, we would need to see the actual code in full.