PIO does not compile local library which leads to linker error

Hello,

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:


lib_problem

+---examples

|   \---test_lib

|       |   platformio.ini

|       \---src

|               test_problem.cpp

+---include

|       libproblem.h

\---src

        libproblem.cpp

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:

platformio.ini:


[platformio]

default_envs    = featheresp32

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

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

[env]

;lib_ldf_mode = deep+

;build_flags = -Llib_problem

[env:featheresp32]

; HW

platform               = espressif32

board                  = featheresp32

framework              = arduino

test_problem.cpp


#include <Arduino.h>

#include "libproblem.h"

void setup()

{

    CLibProblem *lp = new CLibProblem();

    return;

}

void loop()

{

    delay(10000);

}

#if !CONFIG_AUTOSTART_ARDUINO

void app_main()

{

    setup();

}

#endif

libproblem.h:


class CLibProblem {

    public:

        CLibProblem();

};

and libproblem.cpp:


#include "LibProblem.h"

CLibProblem::CLibProblem()

{

   

}

Thank you in advance for the support.

mawi

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.

[platformio]
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!