PlatformIO Community

Build_flags with -I and dependant libraries

My current project has two subprojects. In that I mean there are some devices in the setup running one codebase and another set of devices on another codebase. There is a lot of shared code between the two device rolls.

My structure is below:

ProjectFolder/lib/Common/(random collection of code)
ProjectFolder/Codebase1/(full pio project)
ProjectFolder/Codebase2/(full pio project)

When I add the following to my platform.ini, the files in Common are found.
build_flags = -I ../lib

My problem is that there is code in the Common folder trying to access <WiFi.h> and that is not found. I suspect none of the lib_deps will be found in the Common folder.

Is this the right way to share common code between projects? I would rather not write a library just yet, just sharing source would be ideal.

Thanks!

I don’t think this will make the LDF bite to detect sub-dependencies of these libraries. Also, if those “random collection of codes” are not pure header-only implementations but need certain .c/ .cpp files compiled, this will not work, since -I will not add those files to the build process, it only makes the header files available.

The correct way would be to add the lib\Common folder as a discoverable library by adding the lib folder to the library search path.

lib_extra_dirs = ../lib

(docs)

However, this will then attempt to compile all files in the discovered libraries (i.e., Common), so if anything in there isn’t valid code for your project and fails to compile, the build will fail. You would then need to seperate these code collections into separate libraries that belong together as one unit, or add a library.json with a srcFilter to filter out the unwanted files.

@maxgerhardt Thanks for the clarification. The files are currently written as .h + .cpp files. I will consolidate them into .h only files. Compiling all the code in the folder is not terrible as there is not a ton of logic in there.

Thanks again