Using Library Files without Installing the Library

Kind of a simple question:

I know I can install libraries - done so many times. But I have a Sketch from Hackster/Github and it requires installation of 2 libraries, each containing about 6 files each. I don't really want to install them (1) for fear they may conflict with something else, (2) if I wind up not using the sketch I really don't want the libraries on my computer.

Can I just place all the .cpp and .h files in the same project folder as my .ino Sketch?

Do I remove the #include directives in the .ino file?

If there are embedded #include directives for files that are already in the project folder, will that cause errors?

Thank you.

Yes. You also have the option of leaving the library in its own folder and putting it under the src subfolder of the sketch if you prefer to keep the library packaged in its original form.

No. You still need them. However, they need to be adjusted. Let's say the library's header file is named "Foo.h" and you have this line in your sketch:

#include <Foo.h>

This tells the build system to look for Foo.h in the libraries installation folders. But it's not there anymore. So you need to change it to this:

#include "Foo.h"

This tells the build system to look for Foo.h in the sketch folder, then in the libraries installation folders if it wasn't found in the sketch.

Or if you installed the library to the src subfolder at src/Foo, then you would need to change it to:

#include "src/Foo/Foo.h"

You might find that the library code also made some use of the #include <Foo.h> syntax for the local files. Although not exactly correct, that works fine while the library is installed at a normal location, but it stops working when the library is bundled with the sketch. In this case, you will need to change it to using the correct double quotes syntax.

It's not clear what you are asking. Would you mind providing more details about what you mean by "embedded #include directives" and "project folder" so I can be sure to answer your question correctly?


This is great - thanks for clarifying everything - it all makes sense. Although I've seen it many times, I wasn't aware of the <> vs "" difference.

You actually answered this question before I asked it when you said

Thanks again.

Because either one works usually, the syntax choice seems to often be made at random by programmers in the Arduino world. I think that makes it more confusing to understand the distinction. If they were always used consistently in the code we read, we would gain an intuitive understanding of them over time. Even when either one will work, I always prefer that the most specific syntax was used because it communicates the intent of the developer, making the code more self-documenting.

You're welcome. I'm glad if I was able to be of assistance.

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