Undefined reference : Linker does not find source file but it is in the same folder as the header file

Hello,

I have many questions and issues with the way files are included in platform io. First is that I get linker errors for undefined references even though the definitions are in a .cpp in the same folder as the header containing the declaration.

test_main.cpp:(.text._Z9test_loopv+0x13c): undefined reference to `LoRa_Module::ID_OF_THIS_CARD

Lora_Module.h:

class LoRa_Module

{

    static const uint16_t ID_OF_THIS_CARD;

};


LoRa_Module.cpp:

const uint16_t LoRa_Module::ID_OF_THIS_CARD = CARD_ID;

This ended up being the fix:

lib_extra_dirs = 

    lib/core/LoRa

in the platformio.ini. lib/core/LoRa is the folder in which the files are contained. I would like to understand why this is necessary.

Then next issue is that a header can’t be found fatal error: soft_uart.h: No such file or directory, even though it was found in projects with the very same architecture, and has the following path: lib/soft_uart/soft_uart.h
I tried to do what worked with the undefined references and add

 lib_extra_dirs = 

    lib/soft_uart

to platformio.ini but it still cant find it. And again this works perfectly fine for other projects…

I have had many, many such issues, and am wondering if I broke something somewhere, causing these symptoms. I tried to delete the .pio folder, use a minimal platformio.ini, etc but the problems persist. Im losing my mind.

Is there a comprehensive guide explaining what include paths should look like for pio ? Eg if I have lib/lib1/foo.h , lib/lib2/bar.h, lib/lib2/utils/foobar.h, what would be the paths to include one from another ? The official documentation is rather elliptical.

The first two cases are exactly in the documentation. For lib/lib2/utils/foobar.h, you are using a non-standrad folder structure. It should really be lib/lib2/src/{utils, othermodule, yetanothermodule, library.h} with possibly the subfolders included explicitly as include folders. See

Thank you for the reply, but these links are a bit too concise for me. What should the #include statement look like ? Are relative path recommended, or forbidden ? From src/main.cpp, should it be #include “foo.h” ? #include “../lib/lib1/fooh.h” ? This exact pattern is what is not working (but should ??) in my original question, with the soft_uart.h file. Also those lib1, lib2, and sub(sub)folders therein are not real libs just “filters” I created to organize stuff by functionality. Is there no option to simply include recursively everything in the /lib folder ? I dont want to write an include pamphlet and put library.json s everywhere in my folders… Alternatively, is there a way to structure the files while keeping them all in the same folder, like Visual Studio Community’s filter system ?