Project code parsing issue when using common library code

9 Views Asked by At

I have a problem with Visual Studio Code and IntelliSense extension not able to solve some include statements. Specifically I have a project made of two parts: one is the application code, the other is a common set of functions used by all application projects (as a sort of BSD).

Application code includes parts of the BSD that are going to be used. BSD just include a single folder from application code, that contains the configuration files, specific for this application project (which determines for example the size of buffers, which CPU to target, its pin configuration, the clock speed and so on). The compiler can solve the cross links as it sets the include directories starting from the (main) application code folder and thus the [cfg] folder is found correctly also when compiling the common modules.

A bit of ASCII art for trying to explain the deployment of the modules a bit better.

C:\prj\Test                            C:\prj\lib
src/app                                common/sys
src/cfg                                common/comm
src/usb                                common/extra
+-----------+   include "sys/*.h"      +-------------+
|     - app |----------------------->  |     - sys   |
| App - cfg |   include "comm/*.h"     | Lib - comm  |
|     - usb |----------------------->  |     - extra |
|           |        include "cfg/*.h" |             |
+-----------+  <-----------------------+-------------+

In the example provided, adding C:\prj\Test and C:\prj\lib as include directories for the compiler allows it to find the [cfg] directory correctly for any library modules.c that is going to be compiled. So "comm/uart.c" that includes "cfg/uart_cfg.h" is possible as cfg folder is looked for and found in C:\prj\Test folder (appliction folder). Would I compile C:\prj\AnotherTest project using the same common files library, I had just to state in the application project that the include paths are now C:\prj\Test and C:\prj\lib. Again the cfg folder would be found correctly.

When using Visual Studio Code as a project editor/navigator, I open the project as a workspace adding both folders "App" and "Lib". I also edit the vscode c_cpp_properties.json file to add the include directories for both the folders, and here I have my problem. While the App can easily have Lib in the list of include path, Lib cannot have App in its own, as Lib directory is not used only by the Test app project, and thus cannot have absolute links in its .json file. So when navigating all lib files they show error as they cannot solve the [cfg] includes.

As far as I have seen for Visual Studio Code, each opened folder has its own set of variables and thus ${workspaceFolder} is relative to the specific imported folder and not to what should be the main project. In the end, the Lib folder doesn't know which main project is going to use it and cannot find the relative path to it.

Is there a way to have lib refer to the cfg folder in my application folder other than specifying it as an include path in the .json file? Is there a variable that has higher scope than ${workspaceFolder}?

I hope the problem is clear.

Thanks in advance

CiccioB

0

There are 0 best solutions below