Hi all,
I have a project in which several Arduinos communicate with each other. For this purpose I use a common .h file that contains the common data structures for this special project. This is not a general library, just a common file only for all sketches of this project. All sketch directories are located in a common project directory. The project directory also contains this .h file.
Unfortunately the search path
#include "../communication.h"
does not work. How can I access this common file? I would not like to create it as a general library, because it is specific to this project. The complete project is under git version control and so should be this file too.
I tried with IDE 1.8.9 and with IDE 2.3.2
I know that an absolute path should work, but this is very unflexible. Is there any other solution?
If you're not using Windows, the first suggestion (use sym links) in Define a relative path to `.h` file (C++/ Arduino) - Stack Overflow might do the job. I haven't tested it.
The dumb and easiest way is to copy the common .h file to every sketch folder. The all workarounds, discussed in StackOverflow in the link above - in reality are the nothing but variation of this
The smart way is to create a folder in the Arduino libraries directory and put your .h file there. It haven't to be a "full qualified library", just a folder with file.
So why not make it a library? This would make it easy to include in all of your sketches. You don't have to include it in anything that's not part of this particular project, and it doesn't really hurt to have a library that happens to be used only in a single project/handful of sketches.
The possibly easier way is to use a portable install of IDE 1.8.x for you project. You can keep all your library stuff in the libraries directory (and your common.h will never be in your current library directory) and you can keep all your sketches together.
I often make a dedicated portable install for a project. Advantage is that a backup of the portable install contains everything that you ever need (correct version of IDE, board packages and libraries and your latest sketch(es)).
Because then this file would not be under version control. But it is really part of the project and should be controlled by git as all other project files.
The main problem is that the IDE does not support relative paths to outside the sketch folder.
If there is no other solution maybe the suggestion of @sterretje to have a dedicated portable installation for this project may be best. And then putting the whole sketchbook folder under version control .
Hi @sterretje,
I am using Windows. But indeed you can create symlinks even in Windows on the command line with 'mklink'. And this works like a charm. So the common file(s) for my project are in a directory within the git repository, and the IDE finds them via a symlink to this directory in the libraries folder.
Thanks a lot for your tip.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.