Skip to content
This repository was archived by the owner on Oct 1, 2024. It is now read-only.

Support library development. #1254

Open
Falven opened this issue May 6, 2021 · 0 comments
Open

Support library development. #1254

Falven opened this issue May 6, 2021 · 0 comments

Comments

@Falven
Copy link

Falven commented May 6, 2021

Hello,
When developing a library for Arduino as the documentation states, you are to create the following folder structure:

...Documents\Arduino\libraries\my_project
    - .vscode
        arduino.json
    - examples
        -my_example
            my_example.ino
    - src
        my_header_only_library.hpp
    keywords.txt
    library.properties
    README.adoc

Right now, as far as I know, it only understands sketches. If you try to build without a sketch, it will complain to you.
This makes it impossible to develop a library with proper IDE support.

Fine.
So we add "sketch": "examples\\my_example\\my_example.ino" to our arduino.json and reference our library from sketch.

#include <my_header_only_library.hpp>

Because it's considered a System Library, and our project resides in the System Library location, Arduino knows where to find my_header_only_library.hpp. The problem is, because we are including it as a System Library, Intellisense will not work as Intellisense is only generated for non-system libraries (which is a good thing!)

What if instead, we refer to it via a relative path as a header local to this sketch?

#include "../../src/my_header_only_library.hpp"

Arduino does not respect this syntax; it will only respect local paths that are within our sketch's root directory.
However, if we move our library within the sketch's root directory, then we are no longer a library as we are not following the required structure for a library.

So as far as I can see, the only way to develop a Library using VS Code with Intellisense, static analysis, formatting, etc. support is to create a top-level, temporary, sketch that imports your library and you have to delete it once you're done. Because, otherwise, the plugin will not generate a compile_commands.json that references the library source files.

To make matters worse, this scenario does not support header-only libraries as the generated compile_commands.json does not contain a file declaration for header-only libraries which makes it impossible to develop templated libraries, etc.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant