How i include a file far from the sketch folder

I have a file being created using another program, instead of me copying the file to the sketch folder everytime there is an update to the file, I would like to instead include that file that is in another folder in the sketch.

Right - clicking the file shows me the path

C\My_Projects\scrambler\scrambler.h

and when i try to include it

#include "C/My_Projects/scrambler/scrambler.h"

i get an error saying

fatal error: C/My_Projects/scrambler/scrambler.h: No such file or directory

what is the correct way of doing this?

I don't use a PC but don't you need a colon after the drive letter?

#include "C:/My_Projects/scrambler/scrambler.h"
1 Like

ahhhh ! thank you for that, it can see it now :slight_smile:

have fun with your Arduino !

1 Like

Something to note is that the behavior of the Arduino build system is different for this type of #include directive than for the ones without a path.

When you do something like:

#include <Servo.h>

In addition to the Servo.h file being #included into your sketch file (essentially the equivalent of the #include directive being replaced by the contents of the file), the source files of the Servo library are compiled.

But in this case:

#include "C:/My_Projects/scrambler/scrambler.h"

It is only an include of scrambler.h and nothing more. Any source files under C:/My_Projects/scrambler will not be compiled.

That is probably no problem for your specific application, but I have seen others be confused when they expected it to work just like any normal library installation so I thought I would mention it for the benefit of future readers of this thread.

2 Likes

Thank you for that i will be aware in the future.

Looks like i just got lucky this time the contents of scrambler.h is just a variable, not an actual library

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.