I have a generic c++ library that i'd like to use in an arduino project without making changes to the library code. The library contains subfolders and files in the library include other files of the same library with includes of the form
#include "libraryroot/subfoldername/header.h"
I tried putting 'libaryroot' into C:/Users/Username/Documents/Arduino/libraries but while I can include headers that lie directly inside 'libraryroot' using #include <filename.h>
(not #include <libraryroot/filename.h>
), Arduino fails to find the headers these files include
How can I make use of such a library in Arduino without having to change the library?
-
Check out Platform IO for visual studio code. It is a much better IDE and will let you this type of thing more easily.geometrikal– geometrikal2019年11月03日 09:42:12 +00:00Commented Nov 3, 2019 at 9:42
-
@Juraj I already read this but I still didn't figure out how it can be donematthias_buehlmann– matthias_buehlmann2019年11月03日 12:29:11 +00:00Commented Nov 3, 2019 at 12:29
1 Answer 1
To utilize subfolders with any name in an Arduino library, you must use the 1.5 library specification.
In libraries folder in your sketch folder, create a folder for the library. In this folder create a src
subfolder and put the library source code into that subfolder. Then create a library.properties file in the root folder of the library with some dummy information. Fill the includes
key with the main .h file of the library.
Documents/
Arduino/
libraries/
FooLib/
src/
subfoldername/
header.h
some.h
some.cpp
foolib.h
foolib.cpp
library.properties
In code then use in #include
the path with src folder as starting location.
#include <subfoldername/header.h>