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 <stdio.h>
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