Using code in subfolders

I'm currently doing a project using ethernet and I can NOT afford all the blocking that the existing Ethernet library has. so I'm looking to download a non-blocking version or modify the library myself.

Normally, I would just copy all the CPP and H files of the library into the sketch's folder, but Ethernet has way too many. So I would like to put them in a subfolder.

But it seems like any sort of #include "folder/file.h" causes "No such file or folder" errors, or the files within the folder cannot see each other.

I figure I could also try doing the modified code in a separate library, but I also get "No such file or directory" errors when I try to reference the same files in a new folder.

Hey, is the library a Arduino library? If so, you can find a folder in your "Documents" folder like this:


What I do is I go into that folder and git clone the library into there.Then you can easily use it inside your Arduino IDE. If there is no "libraries" folder, you can just create it.

PS D:\Users\trust\Documents\Arduino\libraries> ls

    Verzeichnis: D:\Users\[Username]\Documents\Arduino\libraries

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       08.06.2018     15:29                Adafruit_NeoPixel
d-----       06.06.2018     18:05                FastLED
d-----       12.06.2018     13:31                NeoPixelBus
d-----       08.06.2018     01:10                pubsubclient
-a----       03.06.2018     18:12            107 readme.txt

Cool. I'll give that a try!

What about subfolders of the sketch? It would be preferable that this modified library travel with the code itself. If I can get it into the sketch folder like I had done in the past, it would also sync with git and I wouldn't have to worry about making sure every computer using this code has the same modified libraries.

I don't think you can use source files in subfolders as the Arduino IDE doesn't search recursively. However you can use Header files.

If you make a subfolder "Test" and place a header file called "something.h" in there, you can include it using:

include "Test/something.h"

You might be able to hack around in the make files, but I'd recommend not putting the library into the sketch folder. Otherwise you'll have to take a look at something like PlatformIO for larger scaled projects.

You can create a folder called src in the sketch folder. In that src folder you can create 'library' folders which will contain the source and include files.

E.g. src/eth/eth.h and src/eth/eth.cpp

You need a reasonably new version of the IDE; 1.8.x should be ok.

You can use #include "full/path/name.cpp"

The reason relative paths don't work is that the IDE copies all the files to another folder before it tries to compile them and then the relative paths are wrong.

I wrote a short Python program that uses the Arduino command line to compile programs and I designed it to deal properly with relative paths by expanding the name to the full pathname before calling the Arduino IDE. Among other things I wanted to be able to share configuration files between different Arduino programs.