当前位置:   article > 正文

PCLint_error 307: can't open indirect file 'au-sm123.lnt

error 307: can't open indirect file 'au-sm123.lnt

转载自:http://blog.csdn.net/feng_ma_niu/article/details/40631521。也进行了一些修改

1 PCLint简介

首先,提供一下PCLint的相关链接:

官网:http://www.gimpel.com/html/index.htm

最新9.0L安装包:http://download.csdn.net/detail/winking324/8162819

百度网盘:http://pan.baidu.com/s/1i3tIqLv

接下来,简单介绍一下PCLint到底是一个什么样的工具。

PCLint是GIMPELSOFTWARE公司研发的C/C++软件代码静态分析工具,可以说,PCLint是一种更加严格的编译器。其主要分为PCLint和FlexeLint,PCLint主要应用于Windows平台,以二进制可执行文件提供,而FlexeLint应用于其他平台,例如Linux,以源代码形式发布。

PCLint在全球拥有广泛的客户群,许多大型的软件研发组织都把PCLint检查作为代码走查的第一道工序。PCLint不但能够对程式进行全局分析,识别没有被适当检验的数组下标,报告未被初始化的变量,警告使用空指针连同冗余的代码,还能够有效地提出许多程序在空间利用、运行效率上的改进点。

总结下来,PCLint就是不通过执行程序进行代码分析,发现代码中潜在的Bug。通过个人实践来看,PCLint可以发现非逻辑上的80%左右的Bug,绝对是C++开发以及测试人员一个强大的助手。

2 PCLint安装及初步配置

安装包主要包含如下两部分:

第一个 Update 为升级包,第二个 Gimpel_PC_Lint_9.zip 为 PCLint 的安装包。

1. 解压 PCLint 的安装包,并进行安装,直接 Next 到最后一步,选择执行配置程序,并点击 Finish 。如果这里没有选择执行配置程序,可以通过执行安装目录下的 CONFIG.exe 来执行配置程序。

2. 接下来弹出 PCLint 的配置程序,点击下一步开始配置。

3. 说明执行完 PCLint 配置后,会生成执行脚本以及 PCLint 的配置文件( *.lnt ),继续下一步。

4. 选择生成路径,安装路径即可,以及文件名称,然后下一步。

5. 选择编译器, VisualStudio 现在最高只有 2008 ,所以只好选择这个了,选择后点击下一步。

6. 选择平台,根据自己的需要,选择对应的平台,这里选择 32bit ,点击下一步。

7. 选择依赖的库,对于 VisualStudio 开发来说,主要包括 Active Template Library(ATL) , Microsoft FoundationClass Library , Standard Template Library , Windows 32-bit 这四部分,选择后下一步。

8. 选择一些特殊的优化建议,例如说代码安全性和效率上的。这里按照最大原则进行选择,有: Scott Meyers(Effective C++ More Effective C++ and Effective C++ 3rdEdition) , Dan Saks , MISRA 2004 ,然后下一步( PS : Effective C++ 这两本巨作真心的给力, C++ 入门必读经典)。

9. 指定当前使用库的头文件所在位置,选择 Create –i options ,并下一步,否则执行 PCLint 时会因为找不到头文件而失败。

10. 选择头文件路径,以分号或者换行( Ctrl + Enter )区分,这里仅添加 Visual Studio 的标准头文件。由于不同的公司或者组织,其文件组织方式可能不一样,又或者包含了其他的各种库,所以有需要可以在这里进行添加,或者执行 PCLint 时出现错误,修改 *.lnt 文件添加即可。

11. 提示是否打开新的配置,选择否。

12. 创建 OPTIONS.LNT 文件,就是简单几个问题,由于我这边显示内容不全,所以选择 No ,然后下一步,如果显示全的话可以分别看一下,就是一些实例代码,然后选择一下即可。

13. 选择对应的开发环境,这里最高只有 VC9 ,所以对应选择这个即可。

14. 添加 PCLint 到系统环境变量中。

15. 经过漫长的配置设定,总算完成了。

3 PCLint更新

经过上面复杂的安装及配置后,接着就需要更新一下 PCLint 程序,使其支持更多的 C++ 检查项等。

1. 解压压缩包中 Update 目录下所有文件到 PCLint 的安装路径,例如我的 PCLint 安装在 D 盘,则对应文件路径应该为:

D:\lint\l9-a-b.lp

D:\lint\lpatch.exe

D:\lint\Update.bat

2. 双击 Update.bat ,进行 PCLint 的更新,更新成功后的结果如图。

最后一行,版本号应该为 9.00L 。如果不正确,请进行路径或者文件是否正确的检查。

另外,说明一下更新的方法,首先,要确定当前 PCLint 的版本号,方法为使用 cmd 定位在 PCLint 的安装路径下,执行 lint-nt.exe–v 即可。其次,去官网上下载最新的更新程序 lpatch.exe 以及更新包(例如 l9-a-b.lp 等),将其拷贝到安装路径下,执行命令lpatch.exe l9-a-b.lp 即可。

4 PCLint的命令行

PCLint主要使用命令行模式来进行文件的解析,这个GCC的编译器过程非常相似。其命令行格式为:

lint options file1 [ file2 file3... ]

既然将PCLint可以当做一个编译器,则options即为编译选项,file即为要编译的文件,对于C++来说,主要是*.cpp文件,由于*.h作为包含文件,是不会进行单独进行编译的,所以这一点需要注意。

如果对一个工程的文件进行检查时,则需要生成文件列表来进行,类似于Makefile文件,所以需要注意一下。

接下来是各个工具的具体配置方法,具体详细的各个参数的信息,还请查阅安装目录下的手册。

5 VisualStudio配置

5.1 扫描并创建cpp文件列表

这个过程就是上面说到的生成文件列表,在Visual Studio中,主要按照工程(或目录)来进行创建。

1. 选择工具,然后创建外部扩展工具。

2. 新建一个外部扩展工具,名称PCLintCreation。

参数如下:

Title:PCLintCreation

Command:安装路径\lint-nt.exe

Arguments:-v -os("$(TargetName).lnt") "$(ProjectFileName)"

Initial directory: $(ProjectDir)

注意: $(ProjectDir)这些宏是vs自定义的,如果需要查看vs中自定义了哪些这种宏,可以打开msdn,然后输入一个常见的宏,比如ProjectName,就可以很方便地查询到定义了哪些宏。

3. 同样,可以根据前文SourceMonitor配置时,进行快捷键的分配。

4. 执行添加的PCLintCreation,会在对应的工程文件路径下,生成一个对应的*.lnt文件,内容如下:

5. 需要注意的是 ,当该工程下文件发生变化时,需要重新执行此任务,保证文件列表的正确性。

5.2 对工程下所有文件进行检查

根据上一步扫描的文件,进行PCLint检查。

1. 选择工具,然后创建外部扩展工具,这个跟上部分的第一步相同。

2. 新建外部工具,名称PCLintCheck。

参数如下:

Title:PCLintCheck

Command:D:\lint\lint-nt.exe

Arguments:-i"D:\lint"std.lnt env-vc12.lnt "$(TargetName).lnt"

Initial directory:$(ProjectDir)

需要注意的有几点 ,第一,由于PCLint对于C++11的支持可能没有Visual Studio 2013支持的那么广泛,所以会检测失败,所以不建议在Visual Studio 2013及以上版本进行使用。第二,第一个lint文件,std.lnt即为上篇文章中配置生成的文件,env-vc12.lnt为VC12(Visual Studio 2013)对应的配置文件,"$(TargetName).lnt"为上一步对工程扫描的文件列表。第三,如果提示缺少*.lnt文件,则将对应的文件拷贝到PCLint安装路径下即可。

注意如果是vs2008,那么需要使用env-vc9.lnt,env-vc9.lnt文件就是普通的文本文件,使用文本编辑工具即可查看它的内容。

如果出现类似Error 307: Can't open indirect file 'env-vc9.lnt'的错误,只需要到安装目录D:\lint下看看有没有‘env-vc9.lnt'文件,如果没有一般在D:\lint\lnt下是一定有的,大家只需要将该文件拷贝一份到D:\lint目录下即可。还可以重启vs试试看。

3. 执行PCLint,会在Output窗口中输出对应的Info,Warn,Error和Fatal等信息,这样根据信息查看对应的代码,并进行改正。

5.3 对单个文件进行检查

如果仅仅是对单个文件进行检查,则不需要配置前两步即可,但这个步骤仅对于单个文件执行检查是有效的,不方便配置到Ant任务中。但是相对于整个工程的检查,效率比较高,所以适合快速检查文件,并修改问题,具体配置如下。

1. 选择工具,然后创建外部扩展工具,这个跟前面相同。

2. 新建外部工具,名称PCLintCheckItem。

参数如下:

Title:PCLintCheckItem

Command:D:\lint\lint-nt.exe

Arguments:-i"D:\lint"std.lnt env-vc12.lnt "$(ItemFileName)$(ItemExt)"

Initial directory:$(ItemDir)

3. 执行PCLint,会对当前文件进行检查,并输出结果到Output窗口中,例如:


6 env-vc9.Int文件

    第五歩中配置参数时都使用到了 env-vc12.lnt这个文件,由于这篇文章是转载的,而作者是以vs2013为例写的教程,所以他使用的是env-vc12.lnt这个文件,而我的编译工具是vs2008,所以使用的是env-vc9.lnt。至于具体某个版本的vs到底应该用哪个版本的env-vc.Int文件,方法很简单,打开env-vc.Int,文件的第一行就是这个Int文件是给哪个版本的vs使用的。

    这个env-vc9.lnt文件内其实就是上面第五歩配置的过程,下面是这个文件的内容。

  1. /*
  2. env-vc9.lnt: environment parameters for Microsoft's Visual C++ 9.0
  3. If you are using Microsoft Visual Studio 2008 and you wish to invoke
  4. PC-lint from that environment then add one or more commands to the
  5. Tools menu as follows.
  6. Simple Check
  7. ------------
  8. For example, to add a simple facility to lint the current file you
  9. may do the following:
  10. 1. From the Tools Menu choose "External Tools ..."
  11. 2. Click the "Add" button.
  12. 3. You will now be able to enter the fields of this Tool.
  13. Modify them so that they approximate the following:
  14. Title: PC-lint (Simple Check)
  15. Command: c:\lint\lint-nt.exe
  16. Arguments: -i"c:\lint" std.lnt env-vc9.lnt "$(ItemFileName)$(ItemExt)"
  17. Initial Directory: $(ItemDir)
  18. X_Use Output Window __Prompt for arguments __Close on exit
  19. Please note that you will have to change the "Command:" path if the
  20. PC-lint Installation Directory is anything other than c:\lint and
  21. you will have to change the "Arguments:" line if the Configuration
  22. Directory is anything other than c:\lint
  23. 4. Select OK to return to the main environment.
  24. This will result in the Tools menu containing the additional item
  25. "PC-lint (Simple Check)". Checking 'X' on 'Use Output Window' is
  26. important because in this way you can advance from error to error
  27. using the F8 key (Shift F8 to reverse).
  28. Strings of the form $(...) are called macros and can be typed in
  29. directly as shown or can be selected from a menu by clicking
  30. a right arrow in the dialog box. $(ItemFileName) refers to the
  31. file name of the currently edited file without its path and without
  32. its extension. $(ItemExt) is its extension. $(ItemDir) represents
  33. the file's directory.
  34. You will probably want to advance your new tool upward into the initial
  35. position of all tools while you are testing and modifying the command.
  36. You can do this by using the "Move Up" button that appears on the External
  37. Tools dialog.
  38. The benefits of using "Initial Directory" are that file-names in lint
  39. error messages will not be so long, and, also, this directory can contain
  40. a std.lnt that overrides the global std.lnt in the Configuration Directory.
  41. This Simple Check is fine to check stand-alone modules but to check
  42. projects or to unit check modules that are in projects we need to
  43. go a bit further ...
  44. Project Creation
  45. ----------------
  46. To lint an entire project we will need the names of all the modules
  47. in the project. Visual Studio keeps these names (as well as some
  48. appropriate options such as define options (-d...) and include options
  49. (-i...) in a file named NAME.vcproj in the current project directory.
  50. NAME is the name of the project and is identified by the macro
  51. $(TargetName). PC-lint can read the .vcproj file and generate the
  52. appropriate .lnt file. We recommend creating a tool for this purpose.
  53. For this tool follow the steps 1-4 doing exactly the same thing as
  54. above except in step 3, the information entered should be:
  55. Title: PC-lint (Project Creation)
  56. Command: c:\lint\lint-nt.exe
  57. Arguments: -v -os("$(TargetName).lnt") "$(ProjectFileName)"
  58. Init. Dir.: $(ProjectDir)
  59. __Use Output Window __Prompt for arguments x_Close on exit
  60. You will need to have an active project before this will work.
  61. If you don't already have one you can obtain an active project
  62. from the Solutions Explorer. You then click the newly added
  63. "PC-lint (Project Creation)" tool on the tools menu to create
  64. NAME.lnt.
  65. The file created is an ASCII file and we recommend that you open it
  66. within the IDE and examine it for any obvious flaws. This is your
  67. chance to make any necessary modifications to the file as the process
  68. of conversion may be less than perfect.
  69. Project Check
  70. -------------
  71. Interestingly, by opening up the NAME.lnt file created above and
  72. running the Simple Check described earlier you have the equivalent
  73. of a full project check. However, we prefer to create a special
  74. Project Check tool.
  75. Now that we have a project file we can create a new tool called
  76. "PC-lint (project check)". For this tool again follow steps 1-4 doing
  77. exactly the same thing as above except in step 3, the information
  78. entered should be:
  79. Title: PC-lint (Project Check)
  80. Command: c:\lint\lint-nt.exe
  81. Arguments: -i"c:\lint" std.lnt env-vc9.lnt "$(TargetName).lnt"
  82. Init. Dir.: $(ProjectDir)
  83. X_Use Output Window __Prompt for arguments __Close on exit
  84. Unit Check
  85. ----------
  86. You can almost do a unit check on any single module by using the
  87. Simple Check scheme suggested above. The only problems are that you
  88. will need a -u option and you will not have the benefit of any -d or
  89. -i options that have been placed into NAME.lnt created in the Project
  90. Creation step. For this reason we suggest the following tool for
  91. doing a unit check of any module that is part of a project and for
  92. which a .lnt project file has been generated.
  93. Title: PC-lint (Unit Check)
  94. Command: c:\lint\lint-nt.exe
  95. Arguments: -i"c:\lint" std.lnt env-vc9.lnt --u "$(TargetName).lnt" "$(ItemPath)"
  96. Init. Dir.: $(ProjectDir)
  97. X_Use Output Window __Prompt for arguments __Close on exit
  98. Note that $(ItemPath) will provide a complete path name and in the
  99. absence of a project.lnt file it would cause full path names to
  100. appear in messages. But a side effect of using the project file
  101. with the --u option means that we adopt the shorter names used
  102. in the project file.
  103. Suppressing Messages
  104. ----------- --------
  105. Suppressing messages is normally done by adding message suppression
  106. options to a file. For example, -e550 will suppress message 550.
  107. There are numerous other options to suppress messages.
  108. As the documentation indicates, the file
  109. c:\lint\options.lnt
  110. (where c:\lint\ is the Configuration Directory) is the presumed container
  111. of your overall suppression policy. (Note: options.lnt is referenced
  112. by std.lnt). Add a message suppression here and
  113. you will affect all linting employing that configuration.
  114. To suppress messages for a particular project (or for all projects
  115. within a given project directory) you may do the following:
  116. Create a file std.lnt that is contained in the project directory.
  117. Make it refer back to the std.lnt in the Configuration Directory.
  118. Then add additional message suppression options or indeed any options
  119. you want. For example it might contain:
  120. c:\lint\std.lnt // reference to original std.lnt
  121. -e550 // project-specific option
  122. In this way suppression is limited to a particular project.
  123. Tool Bar
  124. --------
  125. You also have the option of creating a PC-lint toolbar within your Visual
  126. C++ IDE. First, create one or more tools as described above. You
  127. will need to know the number(s) of the tool(s) you want to place on
  128. the tool bar. This can only be done by the painful and laborious
  129. task of counting. Using the list provided by "Tools"/"External Tools",
  130. jot down the numbers (starting with 1 at the top) of all the tools
  131. to be added to the tool bar. We recommend placing all the PC-lint tools
  132. on a single tool bar. Then select Customize from the Tools menu.
  133. Select the Toolbars tab and click the New... button.
  134. Give the Toolbar a name (E.g., PC-lint) in the dialog box provided and
  135. click "OK". Confirm that the new toolbar is now floating on the
  136. desktop and that a check has been placed in the check box next to the
  137. new toolbar name. Then click on the Commands tab and in the Categories
  138. box, scroll down to and click "Tools". In the Commands box, scroll down
  139. to the appropriate external command number(s) corresponding to the
  140. PC-lint commands you jotted down earlier. Drag the commands from the
  141. Commands box to the toolbar. Their numeric name will change to the
  142. logical name.
  143. If you want to add a button image to the toolbar, you can choose one
  144. via the Modify Selection button. Click Close and you now have your
  145. own PC-lint for C/C++ button. (Note: If you change the location of
  146. the PC-lint menu item on the Tools menu, you will change the subscript
  147. and you will need to change the button(s) on the toolbar.)
  148. */
  149. -"format=%(%F(%l):%) error %n: (%t -- %m)" // Messages will contain
  150. // file information (%F), the line number (%l), the
  151. // message number (%n), message type (%t) and message text (%m).
  152. -hF2 // Make sure we ALWAYS provide file information ('F') and use 2
  153. // lines (one for the source line in error and one for the message).
  154. -width(0) // don't break messages at any particular width
  155. -t4 // Presume that tabs are every 4 stops
  156. +e900 // issue a message at termination.




声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/429605
推荐阅读
相关标签
  

闽ICP备14008679号