To which path defaults #include?

I have two programs sharing the same struct's. I want to put the structs into a separate file (let's say: DATA.h) and include this in both programs in order to avoid errors. I do not want to put DATA.h into a library because it is of local significance only. As I understand it (the reference doesn't mention it) an #include using angular brackets has the library folder as its default path. I thought that #include "DATA.f" would refer to a local path but that appears not to be the case. How can I refer to some local path in my project in an #include statement?

Thanks very much in advance.

Arnold

How can I refer to some local path in my project in an #include statement?

What do you mean by "local path"? Paths are either absolute (C:\Temp\stuff.txt) or relative (.\directory\stuff.txt).

You can use an absolute path in a #include statement, but relative paths won't work, because the IDE copies the file to be compiled to a build directory, so "relative to" loses meaning.

I thought that #include "DATA.f" would refer to a local path but that appears not to be the case. How can I refer to some local path in my project in an #include statement?

Yes.
In my GPS clock, I modified Ladyada's library, thus I wanted to keep it local to the GPS Clock INO. Thus:

#include <SPI.h>
#include "Adafruit_GPS.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9340.h"
#include "GLCD.h"
#include "Utilities.h"
#include <SoftwareSerial.h>
#include <Streaming.h>

You should ensure you have a tab in the Arduino GUI for each .H local headers.

Ray

Thank you both very much for your replies.

PaulS:
What do you mean by "local path"? Paths are either absolute (C:\Temp\stuff.txt) or relative (.\directory\stuff.txt). You can use an absolute path in a #include statement, but relative paths won't work, because the IDE copies the file to be compiled to a build directory, so "relative to" loses meaning.

I want to be able to include a file from another directory, in my case the directory one level up the current directory. As you pointed out I cannot use #include "..\DATA.h", so should use #include "C:\etcera\DATA.h". I didn't know that so thanks very much for your suggestions.

mrburnette:
In my GPS clock, I modified Ladyada's library, thus I wanted to keep it local to the GPS Clock INO. Thus:

#include <SPI.h>

#include "Adafruit_GPS.h"
...




You should ensure you have a tab in the Arduino GUI for each .H local headers.

As far as I know tabs can only be used for files in the same directory. The DATA.h file resides in another directory. You do not explain the difference between #include <DATA.h> and #include "DATA.h". The reference doesn't explain either. Still curous to the difference when there is one.

You do not explain the difference between #include <DATA.h> and #include "DATA.h".

One set of symbols looks in all the Arduino library directories (yours and the core library directory). The other looks only in the sketch directory. It should be obvious which one to use, though which does what is something I have to experiment with every time. Getting old, i guess. 8)

Rnold:
As far as I know tabs can only be used for files in the same directory. The DATA.h file resides in another directory. You do not explain the difference between #include <DATA.h> and #include "DATA.h". The reference doesn't explain either. Still curous to the difference when there is one.

#include "./MAX31855.h"        // Local

Oh, yea of little faith.... Using above syntax you can nest if desired.

Rnold:
I have two programs sharing the same struct's. I want to put the structs into a separate file (let's say: DATA.h) and include this in both programs in order to avoid errors. I do not want to put DATA.h into a library because it is of local significance only.

I don't think this is particularly easy. A library would be the simplest. It only has to consist of this .h file so it's no big deal.

If you are using an operating system that supports it, you could put the file in one sketch folder, and then a "link" to it in the other folder (in Linux and OS/X you could "ln -s filename" to achieve this).


There is another method that I just tested OK.

In one folder, put your sketch and .h file. For example:

foo.h

#include <Arduino.h>

typedef struct {
  int foo;
  byte bar;
} mystruct;

Include_test.ino

#include "foo.h"

mystruct test;

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  }  // end of setup

void loop ()
  {
    
  }  // end of loop

For your other sketch, find the full pathname of the foo.h file and use that, eg.

whatever.ino

#include "/home/nick/sketchbook/Include_test/foo.h"

mystruct test;

void setup ()
  {
  Serial.begin (115200);
  Serial.println ();

  }  // end of setup

void loop ()
  {
    
  }  // end of loop

@Ray, I am sorry of my little faith :slight_smile: But in your example "./file" is the same as "file". You should add an extra dot (and of course move the file one up. Than it gets interesting. In that case only the absolute path yields absolution :wink:

@Nick, this works indeed. Great! This helps to share code between programs without having to put them into a library.

@PaulS. Thanks very much for explaining the difference between #include and #include "file". So the gist is: #include defaults to the Arduino library path, #include "file" defaults to the sketch path and relative paths are not allowed (well, yield something unexpected).