Build with some of the source files hidden from the users

Hi, I would like to allow the PlatformIO project users to edit and see only certain files with the possibility to build the project successfully.

Is there any way for me to do this?

There is the possibility of “hiding” the implementation of something inside a pre-built library file.

Say if you have

void super_secret_logic() {
  //..
}

then you can compile that C/C++ file to a static library, say libSecret.a, and link it in the project (-lSecret). The project then does not require the C/C++ source file anymore, only the header declaring the function. The implementation will be found in the precompiled file.

Note that techniques exists to extract the original C code back from the precompiled library file, that’s called “Reverse Engineering”. Tools like “IDA Pro” and “Ghidra” do a very good job at this. If someone wants to know the logic implemented in a library, they will find it out, only a matter of time. It’s only good enough to push the “casual users” away to look into the implementation.

I’ve written a tutorial on this in How to generate and use pre-compiled objects - #2 by maxgerhardt.

Thanks a lot, men.

So if I have multiple, INO and H files (for example ble.ino, ble.h, hw_control.ino, hw_control,h) I can create a library for each of these pairs?

Yes, but for convienence you should create the library from all sources you want to be ‘hidden’. A precompiled library can have an arbitrary number of object files in it. The tutorial I linked shows how to create such a library.

@maxgerhardt Thank you for your help, your tutorial is great. I just have one question.

Can I create a PlatformIO library using a precompiled library but with multiple headers files? I would like to have one .a file and all headers files from the source without merging everything into one header file like in your example.

That’s absolutely possible. The tutorial did that just for convienience. In general, you can put any combination of .h and .c/.cpp files in a folder in lib/ and use the resulting .a file as a replacement for all .c/.cpp files while keeping all .h files.

2 Likes