How to use pre-compiled object library (.a) in other project files

I have read this tutorial about how to generate and use pre-compiled object (.a) and I can say I succeed to do it.

But I have a question. Does in order to using .a files in another project, we also have to add the .h files so the project can run?

This is my project for build the library (Left) and try on another project without .h file (Right)

I build it and I got .a files in .pio folder just like in tutorial. Then I want to use it on another project that doesn’t have the original .h files (let’s say we build another project in other device that doesn’t contain the original .h file of the library),

I got an error because there is no AtharSyaif.h files on the device. So, I assume that in order to use pre-compiled library in other project, we have to put the .a file and the .h file?, Is that correct? Or I missed something…

  • Can we just use the .a file? If it’s possible then how to do it?
  • Or there are other way to use our own library to another project? maybe upload it or something? idk…
  • Or the only way is put .a file and .h file in your device?

Thank you

Yes, you have.

Correct, again.

No, you can’t.


You’ll always need the corresponding header file (.h)

Normally libraries consist of headers (.h) and implementation files (.cpp).

If you do not want to publish the source code of your implementation, create the precompiled object file (.a).

However, you must provide the interface (.h) to the precompiled object file (.a).
Otherwise the compiler / linker will not know what to do with the .a file.

Unfortunately I can’t explain it any better.


Please describe what your exact intentions are.