An #include statement written as "fileneme.h" will find filename.h in the current sketch directory.
On the other hand, a #include <filename.h> will find the file where?
What directories does arduino use for header files that are not inside the sketch folder and how can a new header file be added to a sketch without the .h file being in the sketch folder?
Here is what I tried to do:
#include <myheader.h>
Then, in c:\users\mike\documents\arduino\libraries\ the file myheader.h was inserted. Didn't work
Then, in c:\users\mike\documents\arduino\libraries\myheader\ the file myheader.h was inserted. Didn't work
Then in the c:\users\mike\documents\arduino\libraries\myheader\SRC\ was added and the file myheader.h was inserted there. Didn't work ether.
Where does arduino search for these and how can you add one?
"#include <filename.h>" and "#include "filename.h"" do the same thing.
They don't (or are not supposed to).
#include "filename.h" will look in the sketch folder first and next in the library directories #include <filename.h> will only look in the library directories
The use of angle brackets (<>) causes the compiler to look for the file on the default path for the library directory. Depending upon installation, this path is the Documents/Arduino/libraries directory on a Windows machine.
The use of double quotes ("") around the header file causes the compiler to look in the sketch working directory for the header file. The default sketch directory can be seen in the File --> Preferences menu option. If the file is not found there, it will also search the default library directory.
"this path is the Documents/Arduino/libraries directory on a Windows machine. "
Yes, but in my original post, that is where I put the myheader.h file and #include <myheader.h> did not find it. There must be more to it than simply putting the header in that directory.
If you want the header file to be found when you place it in the libraries directory you need to place it in a folder of the same name without the '.h'.
tf68:
If you want the header file to be found when you place it in the libraries directory you need to place it in a folder of the same name without the '.h'.
This is incorrect. While it is common practice to do this, it is not required.
The IDE searches many places and directories within those places looking for headers.
bundled libraries, core area, sketchbook libraries, to list a few.
Once it finds the header file, it then creates a -I option to the compiler to add the directory where the header file is found to the compiler search path.
The issue that can arise is when there are collisions. (multiple directories with the same header file name)
Using a directory of the same name as the header will give the directory priority when the header file is found in multiple places.
In the Arduino IDE
Open File|Preferences
At the bottom it defines where the prferences file lives (click it)
C:\Users\XXX\AppData\Local\Arduino15\preferences.txt
ianfinlay_aus:
In the Arduino IDE
Open File|Preferences
At the bottom it defines where the prferences file lives (click it)
C:\Users\XXX\AppData\Local\Arduino15\preferences.txt
I do not have any entry in my preferences.txt file pertaining to hardware or packages. I am running into the same problem in that my version 1.8.9 IDE on a Windows 7 box does not find any of the header files specific to the INO I am trying to compile.
How do I tell the IDE where to look for those files in the project directory under Libraries?