Directory structure and organization

I’m working on a project that has the following directory structure:

lib/
+-- ModuleX/
|    +-- ModuleX_Agent.c
|    +-- ModuleX_Agent.h
|    +-- ModuleX_Errors.h
|    +-- ModuleX_Stub.c
|    +-- ModuleX_Stub.h
+-- ModuleY/
     +-- ModuleY_Agent.c
     +-- ModuleY_Agent.h
     +-- ModuleY_Errors.h
     +-- ModuleY_Stub.c
     +-- ModuleY_Stub.h
src/
+-- MyMain.c

The MyMain.c file includes both ModuleX_Agent.h and ModuleY_Agent.h. The Agents include the respective Stubs and Errors. However, I’m encountering two issues:

  1. This one is not critical but when I had the files structured as

    lib/
    +-- ModuleX_Agent/
    |    +-- ModuleX_Agent.c
    |    +-- ModuleX_Agent.h
    +-- ModuleX_Errors/
    |    +-- ModuleX_Errors.h
    +-- ModuleX_Stub/
    |    +-- ModuleX_Stub.c
    |    +-- ModuleX_Stub.h
    +-- ModuleY_Agent/
    |    +-- ModuleY_Agent.c
    |    +-- ModuleY_Agent.h
    +-- ModuleY_Errors/
    |    +-- ModuleY_Errors.h
    +-- ModuleY_Stub/
         +-- ModuleY_Stub.c
         +-- ModuleY_Stub.h
    src/
    +-- MyMain.c
    

    I could include my libraries as #include <WhateverLibrary.h>, now I can only include them like #include "WhateverLibrary.h".

  2. I also can’t seem to include the Agents in MyMain.c file.

I’m still struggling to understand the correct file/directory structure that I should follow. Can anyone help me understand how I should organize my files?

The folder structure looks correct per readme. If the library dependency finder can’t find a certain lib, there might be conditional includes at play in the code and you might need a different lib_ldf_mode. Does adding lib_ldf_mode = deep+ to the platformio.ini make a difference in compilation?

It might also be the case the Intellisense tricks you and it builds fine. IntelliSense in VSCode is not rebuilt until a build is made (or an explicit Ctrl+Shift+P → Rebuild IntellISense is done).

If that still does not fix the problem, please upload the exact project folder you’re having problems with for inspection.

1 Like

So, some feedback regarding your answer:

First of all, thank you, I’ll accept it as a solution.

Second, I’ve cleaned and built the project with and without adding lib_ldf_mode = deep+ to the platformio.ini file. They both produced the same result. It compiles without warnings but the “problems” tab still “informs” this:
#include errors detected. Please update your includePath. (...)
cannot open source file "ModuleX_Agent.h (I’m trying with just one module)
Is this a case of Intellisense tricking me? Is there a way to indicate to Intellisense this is not a problem?

I’ve tinkered with the includePath. Intellisense works fine now, thank you @maxgerhardt !

Manually? That is almost never good because the .vscode/c_cpp_properties.json (aka, the IntelliSense configuration) is automatically regenerated on build. Does a Intellisense rebuild not work in this case?

If it builds but VSCode complains “File not found :(”, IntelliSense is tricking you.

Manually? That is almost never good because the .vscode/c_cpp_properties.json (aka, the IntelliSense configuration) is automatically regenerated on build. Does a Intellisense rebuild not work in this case?

Yes, manually. I read that warning before changing the file but I don’t know how to rebuild Intellisense (all I can find online mentions restarting VSCode but that doesn’t work) and this seems to do the trick. What should I do to rebuild Intellisense “the right way”?

It’s a PlatformIO provided command in the command palette.

1 Like

Thank you, I owe you one :wink:
I always felt like this forum is much warmer and nicer to people than stackoverflow and I’m glad I had the chance to verify that myself.

2 Likes