VS2008配置PC Lint (静态代码检查工具PC-Lint)
转自 http://hi.baidu.com/spongcer/blog/item/c66cc6f82ea39278034f56b5.html
PC-Lint的典型应用:
1、检查区分int和BOOL。(typedef int BOOL;)
2、未初始化的变量
……
官方地址:http://www.gimpel.com/
也可以到CSDN下载PC Lint 9
Step1:下载完后点击PC-lint.9.0e\pclint9setup.exe进行安装,这里以安装到C:\lint介绍。
安装完成后勾选"I want to run the configuration program now".点击finish进入配置页面,
Step2:配置选项(对应于一个对话框)依次为:
1、C:\lint(这个是pc lint的安装目录),Create a new STD.LNT
2、Microsoft Visual C++ 2008 (co-msc90.lnt)
3、32-bit Flat Model(-ms, -si4, -sp4)
4、勾选常用的库 Active Template Library(ATL),Microsoft Foundation Class Library,Standard Template Library,Windows 32-bit
5、Scott Meyers(Effective C++ More Effective C++ and Effective C++ 3rd Edition),Dan Saks,MISRA 2004
6、Create -i options
7、这里将vc的包含目录加进去,我加的是以下两个
D:\Microsoft Visual Studio 8\VC\include
D:\Microsoft Visual Studio 8\VC\atlmfc\include
8、No (不要选择创建一个新的配置文件)
9、(env-vc9.lnt) Microsoft's Visual C++.NET 2008
10、Prepend my PC-lint directory to my PATH(create LSET.BAT)
完成
Step3:配置好pc lint之后,下面就将它集成到vc2008中
打开vc2008--Tools--External Tools,点击Add按钮Title为pc_lint(这个可以任意命名),
Command为 C:\lint\lint-nt.exe(这个为lint-nt的绝对路径),
Arguments为-i"c:\lint" std.lnt env-vc9.lnt "$(ItemDir)$(ItemFileName)$(ItemExt)",
Initial directory为$(ItemDir),
勾选"Use Output windows",点击OK
Step4:好了,现在写一段程序测试一下吧。main.cpp文件内容如下:
#include
int main()
{
int a;
printf("a = %d\n", a);
return 0;
}
在VC2008中打开该文件,点击Tools--pc_lint,结果如下:
--- Module: C:\Documents and Settings\zwu\Desktop\new.cpp (C++)
printf("a = %d\n", a);
C:\Documents and Settings\zwu\Desktop\new.cpp(6): error 530: (Warning -- Symbol 'a' (line 5) not initialized --- Eff. C++ 3rd Ed. item 4)
C:\Documents and Settings\zwu\Desktop\new.cpp(5): error 830: (Info -- Location cited in prior message)
}
C:\Documents and Settings\zwu\Desktop\new.cpp(8): error 953: (Note -- Variable 'a' (line 5) could be declared as const --- Eff. C++ 3rd Ed. item 3)
C:\Documents and Settings\zwu\Desktop\new.cpp(5): error 830: (Info -- Location cited in prior message)
--- Global Wrap-up
error 900: (Note -- Successful completion, 4 messages produced)
参考网页:
http://blog.csdn.net/orbit/archive/2006/06/23/824505.aspx
http://blog.csdn.net/zhoubinghua2008/archive/2011/01/16/6143769.aspx