PlatformIO Community

Include platformio projects examples into a library folder

Hi :slight_smile:

Here is my problem I have a library folder which is a platformio project and I created a “examples” folder containing different platfomio projects which use this library.

When I launch these projects, I receive a build error. Platformio cannot find the .h file that my project needs.

To be clear, here is the structure of my library:
Library
-------hal (folder)
-------inc (folder)
-------od (folder)
-------src (folder)
-------library.json (file)
-------example(folder)
---------------project(folder)(platformio project)
----------------------------src(folder)
----------------------------inc(folder)
----------------------------module(folder)
--------------------------------------project.c(file)
-------------------------------------- project.h(file)
--------------------------------------library.json(file)

When i lunch the command : platformio run into the project folder the error is

****************************************************************
* Looking for button.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:project.h"
* Web  > https://platformio.org/lib/search?query=header:project.h
*
****************************************************************

 #include "project.h"
          ^~~~~~~~~~
compilation terminated.
*** [.pio\build\l0\src\main.o] Error 1

I have the impression that there is a recursive inclusion problem because when I move the project folder out of my library folder it works.

How can I include a project folder in a library folder?

Thank you in advance for the help

Hi :slight_smile:

Here is my problem I have a library folder which is a platformio project and I created a “examples” folder containing different platfomio projects which use this library.

When I launch these projects, I receive a build error. Platformio cannot find the .h file that my project needs.

To be clear, here is the structure of my library:
Library
-------inc (folder)
-------src (folder)
-------library.json (file)
-------example(folder)
---------------project(folder)(platformio project)
----------------------------src(folder)
----------------------------inc(folder)
----------------------------library(folder)
--------------------------------------project.c(file)
-------------------------------------- project.h(file)
--------------------------------------library.json(file)

When i lunch the command : platformio run into the project folder the error is

****************************************************************
* Looking for button.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:project.h"
* Web  > https://platformio.org/lib/search?query=header:project.h
*
****************************************************************

 #include "project.h"
          ^~~~~~~~~~
compilation terminated.
*** [.pio\build\l0\src\main.o] Error 1

I have the impression that there is a recursive inclusion problem because when I move the project folder out of my library folder it works.

How can I include a project folder in a library folder?

Thank you in advance for the help :slight_smile:

This seems very very uncommon to include a whole PIO project as an example. Usually only the source for the project is included. See e.g. https://github.com/milesburton/Arduino-Temperature-Control-Library

Does the code in your library (src/ or inc/) depend on the project source?

Also why is the message talking about both button.h and project.h when the error is only for project.h?

Hello :slight_smile:
Thank you for your response, indeed the error only concerns project.h.

I see the arduino link that you put but I would like to know how to create an examples folder containing projects when we are not using an arduino but an STM32 microcontroller?

The structure of the examples in PlatformIO does not change whether it’s targeted for an AVR chip or an STM32 chip. The usual workflow is, as I said, to have examples/Example1/*source file(s) for that example* and that’s also how PIO parse the library to get teh “examples” page in a library page being displayed (see e.g. https://platformio.org/lib/show/54/DallasTemperature and code repo)