#include statement with relative path

Hi!

I like to keep my project files in one directory so
I would like to avoid putting classes/librarys inside
the Arduino folder.

I tried using this syntax (Windows machine):

#include "..\AxisCtrl\AxisCtrl.h"

The folder "AxisCtrl" is in the parent directory of
my "prj0009_CNCCtrl_v04.ino" main file.

I also tried:

#include "../AxisCtrl/AxisCtrl.h"

But I always get

prj0009_CNCCtrl_v04.cpp:6:34: error: ..\AxisCtrl\AxisCtrl.h: No such file or directory

Is it even possible to include "local" classes with
relative paths? Im using the Arduino IDE 1.0

Thanks in advance!
Regards!

Move your libraries into a subfolder named "libraries" within your sketchbook folder and you can access them as if the were in the libraries subfolder in the arduino main folder. This means you don't have to specify folders, just the .h files without the equally named folder.

You can also place the files in your sketch's folder and they will be found and compiled in. If you are making project specific changes to the code, this would likely be the better option.

wanderson:
You can also place the files in your sketch's folder and they will be found and compiled in. If you are making project specific changes to the code, this would likely be the better option.

I tried this option but that does not work either.

My folder structure looks like this:
--- Projectfolder (Folder)
--- AxisCtrl (Folder)
AxisCtrl.h
AxisCtrl.cpp
prj0009_CNCCtrl_v04.ino

And I include via

#include "AxisCtrl\AxisCtrl.h"

But I get the same error. :frowning:

If I specify the full path the file is found.
But it would be much nicer to use relative paths or to
put the files in the sketchsfolder. It has to be possible
if you recommended that. What am Im doing wrong? :frowning:

The .h and .cpp files need to be in the same folder as the .ino file, not in a subfolder.

Thanks guys...
but I cant seem to get it work :frowning:
what am Im doing wrong? :frowning:

I attached a screenshot.

You have an unusual folder structure. The standard structure is something like that:

  • sketches
    • libraries
      • AxisCtrl
        • AxisCtrl.h
    • prj0009_CNCCtrl_v04
      • prj0009_CNCCtrl_v04.ino

As you can see the .ino is within a folder of the same name. If structured this way, you don't have to specify folders in the includes, just this:

#include "AxisCtrl.h"

Did you restart the IDE after moving the files? Normally, if you have .h and .cpp files inside the sketch folder, they will be opened as tabs in the IDE, like this:

Tabs.jpg

Thanks pylon and dxw00d!

Solution dxw00d:
After restarting the IDE: it compiled! :slight_smile: Thanks!
The downside is that I cant use a "keywords.txt" for more than
one class used in my project (seperated files).

Solution Pylon:
I think for organisation purposes this solution works for
me. The downside here is that I will/have to change the
skechbook folder for every project because I want the lib-directory
project specific. But I think this is worth the time! :slight_smile:

Thank you guys! :slight_smile: