Creating a custom library - linking error while compliing examples in examples folder [Solved]


I’m writing a library to use openGoPro API on a ESP32 following the folder structure described in Sources (.cpp and .h) for the library is in src folder and examples are in examples folder like below.

    |    |--GoProBLE.h
    |    |--GoProBLE.cpp
    |    |--M5Stack
    |         |--main.cpp

I tried to setup my file platformio.ini like explained here: but I cannot link the example, I have always a link error. I tried to change lib_extra_dirs but I cannot make it work.

PlatformIO\Projects\OpenGoProBLE/examples/M5Stack/main.cpp:53: undefined reference to `GoProBLE::GoProBLE()’
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\ExM5Stack\firmware.elf] Error 1

my platformio.ini file is

platform = espressif32
framework = arduino
board = m5stack-core-esp32


src_dir = examples
lib_dir = ./

lib_extra_dirs =../../
lib_deps =
    m5stack/M5Stack @ ^0.4.6

src_filter = -<*> +<M5Stack/main.cpp>

If anyone knows how to fix it, maybe it’s easy as most libraries follow this pattern

Huh? But if this is from the platformio.ini that is also the library (??), that would exclude the src/GoProBLE.cpp file. Don’t you want to do at least -<*> +<../src/GoProBLE.cpp> +<M5Stack/main.cpp>

Thanks a lot, it works, I thought that lib_extra_dirs would do the trick
Things are easier when library code is in lib folder.