PlatformIO Community

Create Library project in CLion


I want to create a library project. The source code of the project will be used as an library in my other projects.
What is the proper way of doing it?

If I use I get all the dependencies on Arduino SDK and other needed dependencies but when I build I get an error
/var/folders/ly/p8q7k_x50x70vwdzsd5n3s080000gn/T//ccz2FML9.ltrans0.ltrans.o: In function main': ccz2FML9.ltrans0.o:(.text.startup+0x86): undefined reference tosetup’
ccz2FML9.ltrans0.o:(.text.startup+0x8e): undefined reference to `loop’

This particular project doesn’t need setup and loop functions. How should I configure CLion?

In general, regular CMake C++ project should work for me, but how to add Arduino dependencies so I have access to Arduino.h functions

bumping this thread.

Well if you have written a library then surely there are some example sketches that use it? Look e.g. into PIO CI to test-compile these sketches. This is also how many other big libraries do it. (ArduinoJSON). Or create new a project which has unit tests in test/ and use pio test with it, as shown in Unit tests for PIO library or Library testing - pio test.

I think the question is more about setting up CLion to create a library so everything compiles and runs.

From the links you provided it is not clear how to create new project that has only library. CLion IDE plugin creates basic sketch project, should I go and call some CMD commands? can I compile, run tests from IDE?

It looks like there is a missing documentation regarding how to use CLion to create a library.

PlatformIO has no built-in capability to only compile a library (to e.g. a static .a library file) – it must always be done in the context of a sketch / project (then a static library is also a side product, see e.g. How to generate and use pre-compiled objects). As linked, pio ci is basically a shortcut way of compiling a sketch given only the library folder itself and a test sketch file, and that can only be accessed from the commandline, not via any CLion or PlatformIO build target. PlatformIO mainly thinks in projects.

I think you will find it much easier to develop a library if you just create a normal project for your target board / architecture (can also be multiple [env:xyz]), create your library in a new folder in the lib/ folder of the project and develop and test it from there, then pull out the final library folder as the result.

So in this case I kind of have a master project(playground) where /lib folder has libs I want to create. Each lib has library.json, and I push them to git as separate repositories?

Yes that’s possible.