Go Down

Topic: #include statement with relative path (Read 21622 times) previous topic - next topic

asuryan

Jun 20, 2012, 11:03 pm Last Edit: Jun 20, 2012, 11:05 pm by asuryan Reason: 1
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!

pylon

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.

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.

asuryan

#3
Jun 21, 2012, 08:14 am Last Edit: Jun 21, 2012, 08:25 am by asuryan Reason: 1

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? :(

dxw00d

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

asuryan

#5
Jun 21, 2012, 08:46 am Last Edit: Jun 21, 2012, 09:27 am by asuryan Reason: 1
Thanks guys...
but I cant seem to get it work :(
what am Im doing wrong? :(

I attached a screenshot.

pylon

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"

dxw00d

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:

asuryan

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! :)

Go Up