使用PC-Lint与第三方库进行项目。

时间:2023-01-18 00:26:47

I have a project which includes a large third party library and am required to ensure that the project is lint-free. However, the library has several thousand errors.

我有一个项目,其中包括一个大型的第三方图书馆,并且我需要确保这个项目是免费的。但是,这个库有几千个错误。

Modifying the library to remove these is not an option - how would this typically be handled?

修改库以删除它们不是一个选项——这通常如何处理?

Currently, the code is built using Keil uVision and this is where PC-Lint is called from so if this could still be the case that would be best.

目前,代码是用Keil uVision构建的,这是PC-Lint的调用位置,如果这仍然是最好的情况。

Is there a way to specify that these are library files and so should not be analysed?

是否有一种方法可以指定这些是库文件,因此不应该进行分析?

Thanks.

谢谢。

1 个解决方案

#1


7  

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

以下是来自Gimpel网站的信息,我相信它涵盖了你正在寻找的选择(加粗强调):

Lint uses the label of "library" header to designate those headers over which a programmer has no control (such as compiler headers). By default all #includes from a foreign directory, or enclosed within < > , are considered "library." This can be modified through the use of the +libclass option, and further fine-tuned with the +/-libdir and +/-libh options. You can then use the -wlib , -elib and -elibsym options to control just those messages being emitted from library headers. Compiler options files distributed with PC-lint usually contain a -wlib(1) option which limits lint output from library headers to errors only (suppressing warning and informational messages).

Lint使用“库”标头的标签来指定程序员无法控制的头(比如编译头)。默认情况下,所有的#包括从一个外国目录,或包含在< >,被认为是“库”。这可以通过使用+libclass选项进行修改,并与+/-libdir和+/-libh选项进行进一步的微调。然后可以使用-wlib、-elib和-elibsym选项来控制从库标题发出的消息。使用PC-lint分布的编译器选项文件通常包含-wlib(1)选项,该选项限制从库头到错误的lint输出(禁止警告和信息消息)。

You can find more information at the Gimpel site here.

你可以在Gimpel网站找到更多的信息。

Also, if I remember correctly, -wlib(0) suppresses all library errors and warnings... as opposed to the -wlib(1) mentioned above. I will have to double check when I get back to work. I don't have a copy of the manual with me.

另外,如果我没记错的话,-wlib(0)会抑制所有库错误和警告……与上面提到的-wlib(1)相反。我回去工作的时候得再检查一遍。我没有带手册的复印件。

---EDIT---

- - -编辑- - - - - -

If it is an option, I would place all of the files associated with the library in a different directory. In Keil, you can go to "Tools->Set-up PC-Lint". Then add your new directory to the list of "PC-Lint Include Folders". Your -wlib(0) option should then treat those headers as 'foreign' and not return errors. Of course, you would have to modify the project settings to compile the library files as well.

如果是一个选项,我将把所有与库关联的文件放在不同的目录中。在Keil,你可以使用“工具->设置PC-Lint”。然后将您的新目录添加到“PC-Lint包含文件夹”列表中。然后,您的-wlib(0)选项应该将这些头视为“外来”,而不是返回错误。当然,您还需要修改项目设置来编译库文件。

---EDIT2 Added Example---

————-EDIT2添加示例

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

好的,这是一个小测试,我试着确保我的建议行得通。我在名为“ex_lib”的目录中创建了一个项目,并命名为lib_test。在“源组1”中,我创建并添加了文件“main.c”:

main.c

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;
}

I then created a sub-directory named "library" and created a second project named library in that directory. The library project consisted of the following files "lib_test.h" and "lib_test.c".

然后创建了一个名为“library”的子目录,并在该目录中创建了第二个名为library的项目。这个库项目包括以下文件“lib_test”。h”和“lib_test.c”。

lib_test.h

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

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, under "Options for Target 'Target 1'", I selected "Create Library". I then compiled the library project.

在库项目中,在“目标目标1的选项”下,我选择了“创建库”。然后我编译了这个库项目。

After successfully compiling, I went back 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" directory to the "Library" group.

成功编译后,我回到lib_test项目,右键单击“Target1”并选择“Add Group”。我创建了一个名为“Library”的组,并添加了以前编译过的“库”。从“库”目录到“库”组。

Finally, under the options for Target 1 (in the lib_test project), I went to the "C/C++" tab and added "library" to the "Include Paths". I was then able to successfully compile (with some warnings about variables being set but never used) the lib_test project. Under "Tools->Set-up PC-Lint" I added the following:

最后,在目标1的选项下(在lib_test项目中),我选择了“C/ c++”选项卡,并将“库”添加到“Include路径”中。然后,我成功地编译了lib_test项目(其中一些关于变量被设置但从未使用的警告)。在“工具->设置PC-Lint”下,我添加了以下内容:

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

PC-Lint包括文件夹:C:\Keil_ARM\RV31\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \。

Lint Executable: C:\Lint\LINT-NT.EXE

皮棉可执行文件:C:\线头\ LINT-NT.EXE

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

配置文件:C:\线头\ lnt \ CO-RV.LNT

I modified the CO-RV.LNT file to verify my Lint results by modifying -wlib(). When I ran Lint with -wlib(0) I received no warnings or errors about my library files. I then changed -wlib(2) and I received numerous warnings about stdint.h.

我修改了CO-RV。LNT文件通过修改-wlib()来验证我的Lint结果。当我使用-wlib(0)运行Lint时,我没有收到关于我的库文件的警告或错误。然后我改变了-wlib(2),我收到了很多关于stdint.h的警告。

This is definitely an oversimplification but it should give you a good starting point. Also, I received Lint warnings about my variables not being accessed in "main.c" but I expected that.

这绝对是一种过于简化,但它应该给你一个好的起点。而且,我收到了Lint警告,关于我的变量没有被“main”访问。但我希望如此。

#1


7  

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

以下是来自Gimpel网站的信息,我相信它涵盖了你正在寻找的选择(加粗强调):

Lint uses the label of "library" header to designate those headers over which a programmer has no control (such as compiler headers). By default all #includes from a foreign directory, or enclosed within < > , are considered "library." This can be modified through the use of the +libclass option, and further fine-tuned with the +/-libdir and +/-libh options. You can then use the -wlib , -elib and -elibsym options to control just those messages being emitted from library headers. Compiler options files distributed with PC-lint usually contain a -wlib(1) option which limits lint output from library headers to errors only (suppressing warning and informational messages).

Lint使用“库”标头的标签来指定程序员无法控制的头(比如编译头)。默认情况下,所有的#包括从一个外国目录,或包含在< >,被认为是“库”。这可以通过使用+libclass选项进行修改,并与+/-libdir和+/-libh选项进行进一步的微调。然后可以使用-wlib、-elib和-elibsym选项来控制从库标题发出的消息。使用PC-lint分布的编译器选项文件通常包含-wlib(1)选项,该选项限制从库头到错误的lint输出(禁止警告和信息消息)。

You can find more information at the Gimpel site here.

你可以在Gimpel网站找到更多的信息。

Also, if I remember correctly, -wlib(0) suppresses all library errors and warnings... as opposed to the -wlib(1) mentioned above. I will have to double check when I get back to work. I don't have a copy of the manual with me.

另外,如果我没记错的话,-wlib(0)会抑制所有库错误和警告……与上面提到的-wlib(1)相反。我回去工作的时候得再检查一遍。我没有带手册的复印件。

---EDIT---

- - -编辑- - - - - -

If it is an option, I would place all of the files associated with the library in a different directory. In Keil, you can go to "Tools->Set-up PC-Lint". Then add your new directory to the list of "PC-Lint Include Folders". Your -wlib(0) option should then treat those headers as 'foreign' and not return errors. Of course, you would have to modify the project settings to compile the library files as well.

如果是一个选项,我将把所有与库关联的文件放在不同的目录中。在Keil,你可以使用“工具->设置PC-Lint”。然后将您的新目录添加到“PC-Lint包含文件夹”列表中。然后,您的-wlib(0)选项应该将这些头视为“外来”,而不是返回错误。当然,您还需要修改项目设置来编译库文件。

---EDIT2 Added Example---

————-EDIT2添加示例

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

好的,这是一个小测试,我试着确保我的建议行得通。我在名为“ex_lib”的目录中创建了一个项目,并命名为lib_test。在“源组1”中,我创建并添加了文件“main.c”:

main.c

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;
}

I then created a sub-directory named "library" and created a second project named library in that directory. The library project consisted of the following files "lib_test.h" and "lib_test.c".

然后创建了一个名为“library”的子目录,并在该目录中创建了第二个名为library的项目。这个库项目包括以下文件“lib_test”。h”和“lib_test.c”。

lib_test.h

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

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, under "Options for Target 'Target 1'", I selected "Create Library". I then compiled the library project.

在库项目中,在“目标目标1的选项”下,我选择了“创建库”。然后我编译了这个库项目。

After successfully compiling, I went back 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" directory to the "Library" group.

成功编译后,我回到lib_test项目,右键单击“Target1”并选择“Add Group”。我创建了一个名为“Library”的组,并添加了以前编译过的“库”。从“库”目录到“库”组。

Finally, under the options for Target 1 (in the lib_test project), I went to the "C/C++" tab and added "library" to the "Include Paths". I was then able to successfully compile (with some warnings about variables being set but never used) the lib_test project. Under "Tools->Set-up PC-Lint" I added the following:

最后,在目标1的选项下(在lib_test项目中),我选择了“C/ c++”选项卡,并将“库”添加到“Include路径”中。然后,我成功地编译了lib_test项目(其中一些关于变量被设置但从未使用的警告)。在“工具->设置PC-Lint”下,我添加了以下内容:

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

PC-Lint包括文件夹:C:\Keil_ARM\RV31\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \。

Lint Executable: C:\Lint\LINT-NT.EXE

皮棉可执行文件:C:\线头\ LINT-NT.EXE

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

配置文件:C:\线头\ lnt \ CO-RV.LNT

I modified the CO-RV.LNT file to verify my Lint results by modifying -wlib(). When I ran Lint with -wlib(0) I received no warnings or errors about my library files. I then changed -wlib(2) and I received numerous warnings about stdint.h.

我修改了CO-RV。LNT文件通过修改-wlib()来验证我的Lint结果。当我使用-wlib(0)运行Lint时,我没有收到关于我的库文件的警告或错误。然后我改变了-wlib(2),我收到了很多关于stdint.h的警告。

This is definitely an oversimplification but it should give you a good starting point. Also, I received Lint warnings about my variables not being accessed in "main.c" but I expected that.

这绝对是一种过于简化,但它应该给你一个好的起点。而且,我收到了Lint警告,关于我的变量没有被“main”访问。但我希望如此。