Using PC-Lint in a project with third-party libraries

I have a project that includes a large third-party library, and I need to ensure that the project does not contain villi. However, the library has several thousand errors.

Changing the library to remove them is not an option - how will this usually be handled?

Currently, the code is being created using Keil uVision, and PC-Lint is called here, so if that is the same, it would be better.

Is there a way to indicate that these are library files, and therefore should not be parsed?

Thanks.

+6
source share
1 answer

Here is the information from the Gimpel website, I believe that it covers the options you are looking for (highlighted in bold for emphasis):

Lint uses the “library” header label to indicate those headers that the programmer has no control over (for example, compiler headers). By default, all # are included from an external directory or enclosed inside <>, are considered a "library". This can be changed using the + libclass option and is even more finely tuned with the +/- libdir and +/- libh options. You can then use the -wlib, -elib, and -elibsym options to control only messages emitted from the library headers. Compiler parameter files distributed with PC-lint usually contain the -wlib (1) parameter, which limits the output of the string from library headers to errors (suppression of warning and informational messages).

You can find more information on the Gimpel website here .

Also, if I remember correctly, -wlib (0) suppresses all library errors and warnings ... unlike -wlib (1) mentioned above. When I get back to work, I have to double check. I do not have a copy of the manual with me.

--- --- EDIT

If this is an option, I would put all the files associated with the library in a different directory. In Keil, you can go to "Tools-> Set-up PC-Lint". Then add the new directory to the "Folders for enabling PC-Lint" list. The -wlib (0) option should treat these headers as "foreign", and not return errors. Of course, you will have to change the project settings to compile the library files.

--- EDIT2 Added Example ---

Okay, so here is a little test that I tried to verify that my suggestion would work. I created a project in a directory that I called ex_lib, and named the project lib_test . In "Source Group 1" I created and added the file "main.c":

main.c

#include <lib_test.h> int main (void) { uint16_t x = 5; uint16_t y = 10; uint16_t total1 = 0; uint16_t total2 = 0; uint16_t total3 = 0; uint16_t total4 = 0; total1 = add(x,y); total2 = sub(x,y); total3 = mult(x,y); total4 = div(x,y); return 0; } 

Then I created a subdirectory named "library" and created a second project in this directory called library . The library project consisted of the following files: "lib_test.h" and "lib_test.c".

lib_test.h

 #ifndef LIB_TEST__ #define LIB_TEST__ #include <stdint.h> extern uint16_t add(uint16_t x, uint16_t y); extern uint16_t sub(uint16_t x, uint16_t y); extern uint16_t mult(uint16_t x, uint16_t y); extern uint16_t div(uint16_t x, uint16_t y); #endif /* LIB_TEST__ */ 

lib_test.c

 #include "lib_test.h" uint16_t add(uint16_t x, uint16_t y) { return (x + y); } uint16_t sub(uint16_t x, uint16_t y) { return (x - y); } uint16_t mult(uint16_t x, uint16_t y) { return (x * y); } uint16_t div(uint16_t x, uint16_t y) { return (x / y); } 

In the library project, in the section “Parameters for the goal“ Goal 1 ”, I selected“ Create library. ”Then I compiled the library project.

After a successful compilation, I returned to the lib_test project and right-clicked on “Target1” and selected “Add Group”. I created a group called "Library" and added the previously compiled "library.lib" from the "library" to the "Library" group.

Finally, in the Target 1 parameters (in the lib_test project), I went to the "C / C ++" tab and added the "library" to the "Include Paths". Then I was able to successfully compile (with some warnings that the variables are set but never used) in the lib_test project. In the "Tools-> PC-Lint Settings" section, I added the following:

PC-Lint Include Folders: C: \ Keil_ARM \ RV31 \ INC \ and Library \

Lint executable file: C: \ Lint \ LINT-NT.EXE

Configuration File: C: \ Lint \ lnt \ CO-RV.LNT

I modified the CO-RV.LNT file to check my Lint results by changing -wlib (). When I started Lint with -wlib (0), I did not receive any warnings or errors about library files. Then I changed -wlib (2) and I got a lot of warnings about stdint.h.

This is definitely a simplification, but it should give you a good starting point. In addition, I received Lint warnings that my variables are not available in "main.c", but I was expecting this.

+7
source

Source: https://habr.com/ru/post/945893/


All Articles