PlatformIO Community

Is adding additional source directory possible?

Let’s say that I want to add common CPP files to multiple projects. I thought -L would do it, but it does not seem to work.

In this example, I put the common.h and common.cpp to the Common directory and set
“-ICommon -LCommon” to the build flags. It seems that it got the header file, but it shows linkage error: undefined reference to testFunction()’`


What is the -L for, not for CPP files but only actual libraries? If so, is there any way to add a directory for common CPP files that is outside of the “src” directory? If there is no way, please let me know that.

Yes, libraries in the sense of a precompiled libsomething.a file. Not meant for a source file.

They must be in src/ folder or in a library for PlatformIO to trigger its compilation. You can create a folder in which you create a library folder in which you put the common C/C++ files. Two projects can reference this extra library folder via lib_extra_dirs without duplication. This has been asked before, e.g. at Sharing source files between 2 pio projects.