Go Down

Topic: #include file locations (Read 40643 times) previous topic - next topic

PickyBiker

Feb 11, 2016, 07:30 pm Last Edit: Feb 11, 2016, 08:42 pm by PickyBiker
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?

goodinventor

"#include <filename.h>" and "#include "filename.h"" do the same thing.

sterretje

#2
Feb 11, 2016, 07:38 pm Last Edit: Feb 11, 2016, 07:39 pm by sterretje
Quote
"#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
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

econjack

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.

PickyBiker

 "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.

econjack

That path can be different if you installed things differently. What happens if you put it in the current working directory and use double quotes?

Whandall

Did you restart the IDE after creating your directories?
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

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'.

c:\users\mike\documents\arduino\libraries\myheader\myheader.h

And then restart the IDE.

dmhoke

Thanks for the advice. I was having similar problems being able to include certain .h files.

putting it in the Libraries directory in a folder with same name without the .h worked.

hoke

dmhoke

Thanks for the advice. I was having similar problems being able to include certain .h files.

putting it in the Libraries directory in a folder with same name without the .h worked.

hoke

bperrybap

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'.

c:\users\mike\documents\arduino\libraries\myheader\myheader.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.


--- bill

riker1

Hi
I have the same problem.

always certain libraries missing.

even if they are in the "search" folders.

what to do?

Mainly ESP functions

now latest is missing functional   c code, which is present in :

/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/1.20.0-26-gb404fb9-2/xtensa-lx106-elf/include/c++/4.8.2

why is it not found?


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

Now Navigate to:

.\packages\package_name\hardware\samd\X.X.X\Libraries\Library_name\

here are the *.cpp, *.h files

PS: Hm,mmm.  It took reading more than 10 forum threads and finally fumbling myself found the corrcet info!
 

Southerner

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

Now Navigate to:

.\packages\package_name\hardware\samd\X.X.X\Libraries\Library_name\

here are the *.cpp, *.h files

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?

Thank you.

Go Up