Hi! I'm an experienced C programmer but new to Arduino (including IDE 2.2.1).
In doing my projects I have developed a number of utility macros and functions that I commonly want to use, and am getting pretty tired of copy/paste
The IDE documentation I've found is targeted for beginners it seems. I was unable to find answers to these questions:
How can I add a .h include file or directory/folder to the path the IDE searches? I'd like to create/use a new directory/folder to avoid messing with the "standard" ones.
Can anyone please point me to documentation for how to create a library module for the IDE and add it to the library search path?
For the time being I'm using Windows (yuck) but will eventually probably switch to my Linux environment.
That's because the IDE is targeted for beginners. There are other options available (based on Eclipse or VS Code) that provide the ability you're looking for. I'm not sure about Arduino IDE 2.x.
Unlike many IDEs, the Arduino IDE does not give the programmer much access to the command line used to compile and link files, so it is tricky to add a new include path (for example.) (it IS possible, but...)
Instead, the Arduino IDE has a standard location for libraries, and a standard directory structure for informing the IDE about each library. See Library specification - Arduino CLI
Do I have to add the new library via a ZIP file, or can it be created in-place within the library directory? I tried creating it in-place but the IDE isn't recognizing it. Do I have to force a re-index or something like that?
This is exactly what I did. But then #include <mylib.h>
is not finding the file. That's why I was wondering if the IDE needs to reindex or something similar.
Header file is Arduino/libraries/Utility/src/bur.h
Right now there's just a #define macro in the file.
ino file is Arduino/Test/Test.ino
it contains the line #include <bur.h>
When I build it, it says
fatal error: bur.h: No such file or directory"
#include <bur.h>
^~~~~~~
compilation terminated.
exit status 1
Compilation error: bur.h: No such file or directory
I tried restarting the IDE but no change.
This is on Windows 11, IDE 2.2.1
It works if I move bur.h into the same directory as the ino file (and change the #include to use "bur.h" rather than <bur.h>).
At the moment, I don't have anything else in the Utilities directory except for the src subdirectory containing bur.h
Do I have to create a library.properties and keywords.txt file to get it recognized, even if it's just a .h header file?
The keywords.txt file is completely optional regardless of the layout of your library. It is only used to provide keyword highlighting in Arduino IDE 1.x (Arduino IDE 2.x does not use the keywords.txt file).
I just can't get the "flat" approach to work. I presume that by "root of the library" you mean the Arduino/libraries directory.
When I put the file there it isn't found, whether I include "bu.h" or <bu.h>, even if I restart the IDE to force reindexing. It only works if the file is in the sketch directory.