@IraSch (IraSch) posted a new topic, subject "Using Library Files without Installing the Library". It read:

   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.

To which @pert replied

    IraSch:
    
    > Can I just place all the .cpp and .h files in the same project folder as my .ino Sketch?
    
    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.
    
    IraSch:
    
    > Do I remove the #include directives in the .ino file?
    
    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:
    [code] 
        #include <Foo.h>
        
    [/code]
    
    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:
    [code] 
        #include "Foo.h"
        
    [/code]
    
    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:
    [code] 
        #include "src/Foo/Foo.h"
        
    [/code]
    
    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.
    
    IraSch:
    
    > If there are embedded #include directives for files that are already in the project folder, will that cause errors?
    
    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?

So @IraSch (IraSch) replied

    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.
    
    pert:
    
    > It's not clear what you are asking.
    
    You actually answered this question before I asked it when you said
    
    pert:
    
    > You might find that the library code also made some use of the `#include <Foo.h>` syntax
    
    Thanks again.

So @pert replied

    IraSch:
    
    > Although I've seen it many times, I wasn't aware of the <> vs "" difference.
    
    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.
    
    IraSch:
    
    > Thanks again.
    
    You're welcome. I'm glad if I was able to be of assistance.

So @system (system) replied

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


{'source': 'discourse', 'url': 'https://forum.arduino.cc/t/using-library-files-without-installing-the-library/861498', 'title': 'Using Library Files without Installing the Library', 'views': 230, 'has_accepted_answer': False, 'word_count': 682, 'like_count': 2, 'reply_count': 1, 'participant_count': 2, 'posts': 5, 'tags': '', 'author': '@IraSch (IraSch)', 'participants': '@IraSch (IraSch), @pert, @system (system)', 'image_url': [None], 'created_at': '2021-05-13T20:43:17.749Z', 'last_posted_at': '2021-09-10T22:07:13.189Z'}