PIO does not compile local library which leads to linker error


I saw a similar issues very often but somehow I could not solve my problem with existing answers.

I have a “Arduino style” structure with an exampe test program and internal library like this:



|   \---test_lib

|       |   platformio.ini

|       \---src

|               test_problem.cpp


|       libproblem.h



When I compile test_problem (opened test_lib examples folder in VSCode) the includes of the libary are found. However the libproblem library is not compiled and the linker finally has an error:

lib_problem\examples\test_lib/src/test_problem.cpp:6: undefined reference to `CLibProblem::CLibProblem()'

Here are my small test sources:



default_envs    = featheresp32

;lib_extra_dirs  = ${PROJECT_DIR}/../..

lib_dir         = ${PROJECT_DIR}/../..


;lib_ldf_mode = deep+

;build_flags = -Llib_problem


; HW

platform               = espressif32

board                  = featheresp32

framework              = arduino


#include <Arduino.h>

#include "libproblem.h"

void setup()


    CLibProblem *lp = new CLibProblem();



void loop()





void app_main()






class CLibProblem {




and libproblem.cpp:

#include "LibProblem.h"





Thank you in advance for the support.


Can you test the solution in Building and uploading library examples with env sections - #3 by maxgerhardt? You’d also have to move the platformio.ini directly in the lib_problem folder.

Thank you so much, that is in fact the solution. When I was searching I missed this.

Just a follow up question, is there also already a script available which support data folde rin examples for uploading any filesystem?

You can already change that in the platformio.ini’s special [platformio] section, but only for the whole project. Docs.

data_dir = examples/some_example/data

I have not tried this yet, but you could try and change env["PROJECT_DATA_DIR"] as needed, e.g, in reference to the previous script with

    env["PROJECT_DATA_DIR"] = os.path.join(example_path, "data")

In fact extending your previous posted script with this line it allows to have for each example its own data for uploading. - Thank you again very much!