PlatformIO Community

How to create library project?


I want to create new Library for my own projects. Is it possible do this with PlatformIO IDE?

I can create new project that will be focused on concrete boards. But I can’t see the way to create abstract library project with just some .cpp/.h files.


Do you mean common library for a few projects?

  1. Create this common library
  2. Specify lib_extra_dirs in your platformio.ini and add path where this common library is located

See example:


The example library referenced here is not an external library but a de facto Arduino application with a setup and a loop. It remains unclear how one would go about creating an external library since the compiler will throw undefined references to setup and to loop if those are removed.


The OP seems to have been wanting to make a set of .h/.cpp files that could be shared amongst a bunch of projects, which can be done by putting the files in a folder and then referencing that folder via lib_extra_dirs as pointed out. As opposed to putting it in the lib folder, which would then be project specific.

A properly created library, would you would then #include into a main.cpp (for example) won’t cause compile errors.

I do agree that the arduino-external-libs example on github doesn’t seem to be relevant though.

By the way… this is a two year old thread! :open_mouth:


I had realized it was an old thread. Maybe I should have opened a new one? This one seemed most relevant to what I am looking for which is how to create a library project as opposed to an application. This is is how I take the OP’s meaning in the statement “just some .cpp/.h files” – that is to say without a main or a setup and loop.

It seems that one can create an external library and develop it within the context of another application, but as far as I can tell there is not a way to create and develop a library on its own with unit testing. Thus it seems to me that the question remains unanswered.


Have you tried platformio ci -l . command?


$ pio ci -l .
Usage: pio ci [OPTIONS] [SRC]…
Error: Invalid value: Missing argument ‘src’

So, not sure yet what I am doing wrong, but looking at the ci document page, this does seem to be on the right track. Particularly:

" platformio ci command is useful for library developers. It allows one to build different examples without creating own project per them."

I guess some additional documentation on how to do that exactly would be super helpful. In the mean time, I’ll dig into the ci command a bit more.

thank you


Ah, I got you… you want to test a library?

There may be some more info here also :

I’m assuming here that when using the pio ci option that the examples for the library will be automatically built… or that’s at least vaguely what the docs suggest.