Can Lint resolve the include path of Header Files

4.3k views Asked by At

I have setup one Project Folder in which i have main Project Directory, say Main_Proj. In that folder, I have created two folders for Header_Files and Source_Files.

Folder Header_Files only contains all header files. lets say module_1a.h and so on. Whereas, folder Source_Files contains main.c and again module wise folders, lets say Module_1 which only contains required .c files of particular module. So for example, folder Module_1 contains Module_1a.c and Module_1b.c.

So the path for Module_1a.c would be =

Main_proj\Souce_Files\Module_1\Module_1a.c

and in all source file I have included the Header Files like below -

//Code for Module_1a.c
#include "..\..\Header_Files\Module_1a.h"
....

My IDE is MP LAB and this code and all modules are working fine with MP LAB xc8 compiler.

Problem occurs when i started Linting my code, its giving me error like -

Error 322: Unable to open include file '....\Header_Files\Module_1a.h'

I am using PC Lint for C and C++ (version 9). I searched for resolution of this error in Regference manual and got to know to include that directory with -i option.

I also checked with set INCLUDE=<directory Path> but its not working.

Is there any thing i can do with my std.lnt file or do i have to change the folder structure for my Project?

2

There are 2 answers

0
Joe On

One solution is to use the flag

+fdi // #include search in the directory of the including file

see Error 322 at https://www.kessler.de/prd/gimpel/pclint-meldungen.htm

or

https://www.bezem.de/pdf/htwpl.pdf

or

https://www.gimpel.com/archive/pub90/read90.txt (Section Microsoft's nested #include search)

0
Jens On

Any source code tree organization where headers or paths contain .. is broken as designed.

The way to go and do away with a lot of problems is

  • have a single project root directory
  • Use -I. when compiling, linting, preprocessing, static analyzing, ...
  • all file references in headers and the project makefile are as seen from the project root

I.e. a header includes other headers using

#include "subdir/whatever/foo_module.h"

and all compilation happens with the working directory being the project root, e.g.

subdir/whatever/foo_module.o: subdir/whatever/foo_module.c
    $(CC) $(CFLAGS) -I. -o $@ $<

This keeps -I lists extremely short; ideally only -I..