Arduino Forum

Using Arduino => Programming Questions => Topic started by: asuryan on Jun 20, 2012, 11:03 pm

Title: #include statement with relative path
Post by: asuryan on Jun 20, 2012, 11:03 pm
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):
Code: [Select]
#include "..\AxisCtrl\AxisCtrl.h"

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

I also tried:
Code: [Select]
#include "../AxisCtrl/AxisCtrl.h"

But I always get
Code: [Select]
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!
Title: Re: #include statement with relative path
Post by: pylon on Jun 20, 2012, 11:19 pm
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.
Title: Re: #include statement with relative path
Post by: wanderson on Jun 20, 2012, 11:26 pm
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.
Title: Re: #include statement with relative path
Post by: asuryan on Jun 21, 2012, 08:14 am

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
Code: [Select]
#include "AxisCtrl\AxisCtrl.h"

But I get the same error. :(

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? :(
Title: Re: #include statement with relative path
Post by: dxw00d on Jun 21, 2012, 08:33 am
The .h and .cpp files need to be in the same folder as the .ino file, not in a subfolder.
Title: Re: #include statement with relative path
Post by: asuryan on Jun 21, 2012, 08:46 am
Thanks guys...
but I cant seem to get it work :(
what am Im doing wrong? :(

I attached a screenshot.
Title: Re: #include statement with relative path
Post by: pylon on Jun 21, 2012, 10:38 am
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:

Code: [Select]
#include "AxisCtrl.h"
Title: Re: #include statement with relative path
Post by: dxw00d on Jun 21, 2012, 10:43 am
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:
Title: Re: #include statement with relative path
Post by: asuryan on Jun 21, 2012, 11:10 am
Thanks pylon and dxw00d!

Solution dxw00d:
After restarting the IDE: it compiled! :) 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! :)

Thank you guys! :)