Include header from another directory

Hi! I have the following dir structure:

myArduino/arduino.ino include/test.h

with myArduino and include in the same directory, they are on the same "level"

Now to the question. I want to include test.h in my .ino with this structure. I need it to be like this for git. I've tried: (win7)

#include "..\include\test.h"
#include "../include/test.h"

but neither works. Should it work or is there any other way?

Many Thanks, Calle

The problem is that you're acting as if you're in a conventional C++ environment, but you aren't.

The Arduino IDE follows its own set of rules to scrape together the set of files that it thinks are necessary to build your sketch, including to doing some manipulation to your sketch .ino file(s) to generate C++ files from them, and then tries to compile the whole lot. It does all this in a temporary directory which means that relative file references relative to your source directory won't work.

There are a couple of ways to include multiple files within your sketch in the Arduino scheme. The first way is to dump all your files in the directory that your sketch .ino file(s) are in. All files here will be copied to the temporary directory before compilation. The second way is to crate an Arduino library and reference it within your sketch. An Arduino library is a directory under the library directory within the Arduino software installation directory, or under the library directory within your Arduino sketch directory. The name of the directory is the name of the library. There must be a header file with the same name (with a .h extension). To reference the library, #include the header file in your sketch .ino file. Note that you only include the file name of the header file (#include "foo.h") and don't include any elements of the path. When you reference the library, all the source and header files in the library directory will be copied to the temporary directory and compiled into your sketch.

In C++ terms it's a bizarre and unintuitive process, but that's how the Arduino guys decided to do it.

That's some bad news! It doesn't seem to hard to implement this feature since every programming languages has it.

Is there any way with linked folder or something along those lines? For git I really need them in the same folder so maybe need to mash everything up in one folder, that will suck. Is it the same problem if I use visual stuido for Arudunio?

Thanks!

Aladdin:
but neither works. Should it work or is there any other way?

Make a library instead. Just put all .cpp and .h files into a separate folder, and put that inside the libraries folder (under where your sketches go).

People make quite large projects that way. Then you can use git to control the entire library folder (and separately, the sketch folder if you need to).

[quote author=Nick Gammon link=topic=178017.msg1320531#msg1320531 date=1374129330]

Aladdin: but neither works. Should it work or is there any other way?

Make a library instead. Just put all .cpp and .h files into a separate folder, and put that inside the libraries folder (under where your sketches go).

People make quite large projects that way. Then you can use git to control the entire library folder (and separately, the sketch folder if you need to). [/quote]

But then I have to setup a new git repo because the libraries need to be in a special folder, right? I also want them in the same folder so I don't need to jump between folders.

It's hardly in the same folder:

#include "../include/test.h"

That's the include folder in the level up.

Re: Include header from another directory

I also want them in the same folder so I don’t need to jump between folders.

Do you want “another directory” or “the same folder”?

Sorry for being unclear!
I have this folder structure:

  • gitFolder

  • include

  • myArduino

And since one git repo cant connect to several folders everything need to be in “gitFolder”. If you have one .ino - repo and one lib-repo you will sometimes miss to push/pull one of them and hell breaks loose.

Have you tried putting the include directory underneath the sketch directory?