安裝
將壓縮包比如pclint8.zip拷貝到c:\,解壓后重命名目錄為c:\pclint
不用任何配置,直接使用
準備待被檢查的文件:
先在E:\建一個文件:main.cpp,內容為:
void main()
{???
}
最簡單的用法
在命令行下輸入:D:\>C:\PCLint\Lint-nt E:\main.cpp
C:\PCLint>C:\PCLint\Lint-nt E:\main.cpp
PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004
--- Module:???? E:\main.cpp
_
}
E:\main.cpp??? 3??? Info 783: Line does not end with new-line
C:\PCLint>
PCLINT已經工作了,是不是簡單的難以讓人相信。
最簡單的標準用法
修改被檢查的文件E:\main.cpp,內容修改為:
#include <stdio.h>
void main()
{
????? printf("hello pclint\n");???
}
再次在命令行下輸入:D:\>C:\PCLint\Lint-nt E:\main.cpp
D:\>lint
PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004
--- Module:???? E:\main.cpp
?????????? _
#include <stdio.h>
E:\main.cpp??? 1??? Error 322: Unable to open include file 'stdio.h'
D:\>
報錯誤,“不能找到頭文件stdio.h”
當然PCLINT不可能也不應該知道到哪里去找stdio.h,stdio.h所在的路徑需要我們告訴它。
如何告訴呢?
通常的做法是在xxx.lnt文件中指定,然后指定使用這個xxx.lnt文件。
最簡單的是使用 c:\pclint\std.lnt 這個文件。
std.lnt的配置:
修改std.lnt
運行C:\PCLint\CONFIG.EXE(或者直接手工修改std.lnt)
最后生成的std.lnt內容為:
//??? Microsoft C and Visual C++ 6.x, -si4 -sp4,
//??? Standard lint options
co-msc60.lnt
// options.lnt??? -si4 -sp4
-i"E:\Program Files\Microsoft Visual Studio\VC98\Include"
-i"E:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE"
-i"E:\Program Files\Microsoft Visual Studio\VC98\ATL\INCLUDE"
暫時將options.lnt 這行注釋掉。
注:如果生成的std.lnt內容與上面不一樣,可以手工修改成上面那樣。
使用std.lnt
再次在命令行下輸入:D:\> C:\PCLint\Lint-nt -i"C:\PCLint" -u std.lnt e:\main.cpp
C:\PCLint\Lint-nt -i"C:\PCLint" -u std.lnt e:\main.cpp
-i"C:\PCLint" -u std.lnt 指明使用std.lnt這個選項文件,至于std.lnt在什么目錄,通過-i"C:\PCLint"告知。
至此,我們已經學會了PCLINT的簡單用法及兩個選項:-i,-u
-i 指明包含路徑
-u 指明使用哪些.lnt文件
前面我們掌握了命令行方式下PCLINT的使用方法,下面介紹在VC下面的配置及使用。
3.1. VC下的配置
新建一自定義工具項,名稱為:PCLINT
其中的Arguments為:-i"C:\PCLint" -u std.lnt env-vc6.lnt "$(FileName)$(FileExt)"
Q:怎么知道要輸入這樣的參數了?
A:從幫助中得知的,見文件env-vc6.lnt
Q: env-vc6.lnt有什么作用?
A:指定輸出錯誤報告的格式,這個選項可以去掉,比如修改為:
Arguments為:-i"C:\PCLint" -u std.lnt "$(FileName)$(FileExt)"
3.2. 示例
3.2.1.????? testForPclint1
新建一個最簡單的Win32 Console Application,工程名testForPclint1,其中的main.cpp為:
void main()
{???
}
點擊Tools菜單下面的PCLINT菜單項:
PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004
--- Module:???? main.cpp
}
main.cpp(3): error 783: (Info -- Line does not end with new-line)
--- Global Wrap-up
error 900: (Note -- Successful completion, 1 messages produced)
Press any key to continue
第三行有個錯誤:error 783: (Info -- Line does not end with new-line)
意思是說沒有以新行結束。
注:如果Arguments為:-i"C:\PCLint" -u std.lnt "$(FileName)$(FileExt)"
則結果為:
PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004
--- Module:???? main.cpp
_
}
main.cpp(3) : Info 783: Line does not end with new-line
Press any key to continue
修改main.cpp為:
void main()
{???
}<---即在這里加一個回車
再次LINT,結果沒有任何告警:
PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004
--- Module:???? main.cpp
--- Global Wrap-up
error 900: (Note -- Successful completion, 0 messages produced)
Press any key to continue
3.2.2.????? testForPclint2
新建一個最簡單的Win32 Console Application,工程名testForPclint2,其中的main.cpp為:
#include "stdio.h"
int main(int argc, char* argv[])
{
????? printf("hello\n");
}
點擊Tools菜單下面的PCLINT菜單項:
PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004
--- Module:???? main.cpp
_
}
main.cpp(6) : Warning 533: function 'main(int, char **)' should return a value
????? (see line 3)
main.cpp(3) : Info 830: Location cited in prior message
_
}
main.cpp(6) : Info 715: Symbol 'argv' (line 3) not referenced
main.cpp(3) : Info 830: Location cited in prior message
_
}
main.cpp(6) : Info 818: Pointer parameter 'argv' (line 3) could be declared as
????? pointing to const
main.cpp(3) : Info 830: Location cited in prior message
_
}
main.cpp(6) : Info 715: Symbol 'argc' (line 3) not referenced
main.cpp(3) : Info 830: Location cited in prior message
Press any key to continue
有4個告警,修改main.cpp為:
#include "stdio.h"
int main(int argc, char* argv[])
{
????? (void)argc; // pc lint
????? (void)argv; // pc lint
????? printf("hello\n");
????? return 0;
}
再次LINT,無任何告警了。
PC-lint for C/C++ (NT) Ver. 8.00q, Copyright Gimpel Software 1985-2004
--- Module:???? main.cpp
Press any key to continue
4.???? 使用批處理方法
為什么要使用批處理?還不是為了使用更簡單。
我們在C:\PCLint建一個批處理文件lint.bat,內容為:
@echo off
C:\PCLint\Lint-nt -i"C:\PCLint" -u std.lnt e:\main.cpp
為了支持輸入參數,修改為:
@echo off
C:\PCLint\Lint-nt -i"C:\PCLint" -u std.lnt %1
這時候我們不能簡單輸入D:\>lint.bat,而必須加上輸入參數:
D:\>lint.bat e:\main.cpp
////////////////////////
二,pc??? lint??? 在幾個編譯器的配置???
??????
?? 人云亦云實在不是個好行為-----網絡上都那樣一致的說法讓我走了不少彎路??? 。?????
??????
??????
?? 好了言歸正傳,開始配置pc??? lint??? .?????
??????
?? 以下假設您已經把pc??? lint??? 安裝在C盤下(c:\pclint)???
?? (其他目錄也可以)???
??????
?? 我們不必要將c:\pclint\lnt??? 下的???
?? 3個文件lib-w32.lnt,env-vc6.lnt,co-msc60.lnt拷貝至c:\pclint下,???
?? 那樣簡直是擾亂視線,而且還會引起麻煩??? ;???
??????
?? 也不必在安裝目錄下創建std.lnt和options.lnt兩個文件??? !???
??????
?? 因為我要設置VC6,??? Source??? Insight??? 及Keil??? C51等編譯器,???
??????
?? 所以不是一個std.lnt就能解決問題的??? !???
??????
?? 我的做法是:??? 一類編譯器一個lnt文件,基本屬于"不動產" .?????
?? e.g.??? :?????
?? vc6_0.int???????
?? //??? vc6_0.int??? content??? for??? VC6??? .???
?? //************************************************************************???
?? //************************************************************************???
??????
????
?? //??? compile??? environment???
?? c:\pclint\lnt\env-vc6.lnt???
??????
????
?? //??? system??? lib??? include??? .???
?? c:\pclint\lnt\co-msc60.lnt???
?? c:\pclint\lnt\lib-w32.lnt???
??????
????
?? //??? system??? stdio??? hearder??? files??? directory??? .???
?? -i"D:\Program??? Files;D:\Program??? Files\Microsoft??? Visual??? Studio\VC98\Include"???
??????
????
?? //??? user's??? defined??? lint??? configure??? file??? .???
?? G:\work\eva_skype\eva_skype_pc\vc.lnt??? -si4??? -sp4???
si3_5.int???????
?? //??? si3_5.int??? content??? for??? Source??? Insight??? .???
?? //************************************************************************???
?? //************************************************************************???
??????
????
?? //??? compile??? environment??? .???
?? c:\pclint\lnt\env-si.lnt???
??????
????
?? //??? system??? lib??? include??? .???
?? c:\pclint\lnt\co-msc60.lnt???
?? c:\pclint\lnt\lib-w32.lnt???
??????
????
?? //??? system??? stdio??? hearder??? files??? directory??? .???
?? -i"D:\Program??? Files;D:\Program??? Files\Microsoft??? Visual??? Studio\VC98\Include"???
??????
????
?? //??? user's??? defined??? lint??? configure??? file??? .???
?? G:\work\eva_skype\handset\app\si.lnt??? -si4??? -sp4???
??????
????
?? //************************************************************************???
?? //************************************************************************???
??????
??????
??????
??????
?? kc51.lnt???
?? //??? kc51.lnt??? content??? for??? Keil??? C51??? .???
?? //************************************************************************???
?? //************************************************************************???
??????
????
?? //??? compile??? environment??? .???
?? -i"c:\pclint\lnt\evn-keil.lnt"???
??????
????
?? //??? system??? lib??? include??? .???
?? c:\pclint\lnt\co-kc51.lnt???
??????
????
?? //??? system??? stdio??? hearder??? files??? directory??? .???
?? -i"D:\Program??? Files\EVA_KEILC51\C51\INC"???
??????
????
?? //??? user's??? defined??? lint??? configure??? file??? .???
?? G:\work\eva_skype\handset\kc.lnt??? -si4??? -sp4???