Go Down

Topic: Modify a library for a specific sketch only (Read 541 times) previous topic - next topic



Most of my sketches use the libraries just like they were developed by the Community. However, for some I need slight modifications. Is there any way to keep such modified versions of the libraries specifically for a given sketch?

I imagined this could be achieved by creating the "libraries" folder in the sketch's folder, but libraries are not detected by the IDE/compiler there.


include the files in the same directory, and change the #include<library.h> to #include "library.h"
http://www.uk-pcb.co.uk - UK Based PCB Fab Company
I will code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.


When you put library files in the sketch folder they are all shown as tabs in the Arduino IDE. This may be desirable since it allows you to view and modify the library source. However, it also clutters up the Arduino IDE if you only want to work on the sketch and if you do this with multiple libraries the sketch folder will get very messy. Also, that won't work with libraries that have source files in separate subfolders.

Another option is to put the libraries under the src subfolder of the sketch folder. For example, say you have a sketch named foosketch and a library named foolib, the folder structure would look like this:


Include in the sketch like this:
Code: [Select]
#include "src/foolib/foolib.h"

Note this usage is only supported in recent versions of the Arduino IDE.

When you put libraries in the sketch folder, whether in the root or src subfolder, you will encounter a compilation error if any of the library files use the #include <foo.h> syntax to include internal library files. Although incorrect, this works when the library is located in a standard library folder so it's a common problem. The solution is to simply modify the library source to use the #include "foo.h" syntax.


You are asking for trouble having different versions of the same library still under the same name, just in different folder locations. 

Better to derive a new libary with a new name from the original library, make the desired mods to it and reference it under the new name in the #inclue statement the main .ino file.

 I added functionality to a published Sparkfun ESP8266 library in this way, then use it instead of the original. Works great!

Go Up