Libraries with Multiple cpp Files

I’ve searched the documentation and haven’t really been able to find a solution. I have a private library that contains multiple header and source files. For example, my project structure looks something like this:

├ lib
| └ LibA
|    ├ LibA.h
|    ├ LibA.cpp
|    ├ DataStructure1.h
|    ├ DataStructure1.cpp
|    ├ DataStructure2.h
|    └ DataStructure2.cpp
├ src
| └ EmbeddedProject.ino
└ platformio.ino

With this structure, the linker is complaining, for example, of an undefined reference to DataStructure1::insert(int). I could just put everything into a single file, but I feel like that defeats the purpose of even structuring the code into independent libraries to an extent.

My platformio.ino file is pretty straightforward, I haven’t changed anything from the default generated automatically by PIO except for playing around with the lib_ldf_mode (I’ve tried changing it to deep and deep+). As suggested elsewhere, I have tried to #include the header files for DataStructure1 and DataStructure2 in the EmbeddedProject.ino file as well as the LibA.cpp file, but this did not seem to solve the problem.

So, is there a way to support libraries with multiple cpp files? If so, how? If not, is there a suggested work around? Regardless of the answer, it would be nice to see documentation on the matter.

Can you upload a ZIP of your project (or a minimal example that reproduces the error)? Google Drive or Dropbox should work.

Sure, I’ll try to produce a minimal reproducible example (no need to go through all my code). I’ll upload it when I get something working, but your reply suggests it should be working on my end. Hopefully it’s just some simple oversight on my part.

In the end, the error was mine. I declared a template class and forgot to #include the source file with the definition in the header.

However, it would be nice to see in the documentation somewhere (perhaps the readme.txt file generated in the lib directory) an example with multiple source/header files just to know PIO can handle it. It would help those like me that make a simple mistake narrow down the possibilities a little faster.

Anyways, thanks for the quick response. You can close this issue if possible on this system.

@c1moore good to know that it’s fixed. You can mark your own pots as a solution/answer with a button under it somewhere to close the question.