PC-Lint software usage
1. installation and configuration
PC-Lint software is cost-effective, easy to learn, easy to promote and solidify into the software development and testing process, so it has been widely used in the world. PC-Lint is easy to use. You can use the command line method. For example, lint-NT-u STD. LNT test1.c test2.c test3.c can also use makefile. In addition, it can also be integrated into many development environments or commonly used code editing software, such as integration into source Insight/slickedit/MS vc6.0/Keil C... and so on. PC-Lint also supports various methods described in Scott meyes's popular C ++/more effective C ++ to improve efficiency and prevent errors.
PC-Lint installation is very simple. Take PC-Lint 8.0 as an example. Run the installer to release it to the specified installation directory, such as C:/pclint8. After that, run the configuration tool config.exegenerate and check the configuration file of pc-lint. for example, config.exe should be located at: C:/pclint8/config.exe. The configuration file is the basis for code check. PC-Lint comes with a standard configuration file STD. LNT, but this file does not contain directory information (header file directory), usually you need to specify some special include directory during code check, therefore, you must generate a custom configuration for code check of a project based on the standard configuration. The following uses the Microsoft Visual C ++ 6 development environment as an example to describe the process of custom configuration.
After running C:/pclint8/config.exe, a welcome page is displayed, indicating the copyright information, as shown in Figure 4.1:
Figure 4.1 welcome window for configuration
Click "Next" and click "Next" to find out the pc-lint.exe command line instructions window (Figure 4.2 ):
Figure 4.2 pc-lint.exe command line instructions window
Click "Next" to continue, and then select the options to create or modify the existing configuration file STD. LNT:
Figure 4.3 select how to use the configuration file STD. LNT
Because this is the first configuration, select the above option "Create a new STD. this will not modify the existing configuration file STD. the content of LNT is to create a new std_x.lnt file. The X in the file name is any of the 26 English characters from "A" to "Z", which is generally arranged in order, start with ". The content of the std_x.lnt file is initialized as a copy of the STD. LNT content. 4.3, use the default PC-Lint path, and click "Next" to select the compiler:
Figure 4.4 select Compiler
Next, select the compiler. In the drop-down box, select your own compiler. Here we select Microsoft Visual C ++ 6.x (co-msc60.lnt )". If you do not have your own compiler, you can select the generic compiler "generic compilers ". This option will be reflected in the co-xxx.lnt file and stored in the previous configuration path we selected (C:/pclint8), followed by the configuration option we selected ***. LNT will be stored in this path. Click "Next" to select the memory mode:
Figure 4.5 select memory mode
You can select an appropriate memory model based on the actual size of your own program and data zone. The memory model options are reflected in the STD. LNT file or the newly created std_x.lnt. Because our development environment is a 32-bit windows, select "32-bit flat model" and click "Next" to select the configuration information of the desired supported database:
Figure 4.6 select the configuration information of the software library
PC-Lint provides custom configuration information for some commonly used software libraries. Choosing these custom information helps developers to focus their attention on errors or information in their own code, the selected supported library configuration will be introduced to STD. the LNT file or the newly created std_x.lnt file. Select common ATL, MFC, STL, and other configurations, and then click "Next:
Figure 4.7 programming recommendations for choosing a software celebrity
This is an interesting option, that is, to allow you to choose whether to support some personal opinions on programming from the authors who have made important suggestions for using C/C ++ programming. If you select an author's suggestion, the options for his proposed programming recommendations will be turned on, the author's suggested configuration is AU-xxx.LNT, it is recommended to select all, and then click the next button:
Figure 4.8 select whether to set the directory containing files
Next, select how to set the include file directory. If you select-I to help set the include file option, the next step requires entering one or more include paths. You can also skip this step and manually modify the configuration file later. The-I option is embodied in STD. in the LNT file or the newly created std_x.lnt file, each directory is prefixed with-I. The directories are separated by spaces. If the directory name contains a long file name or contains spaces, double quotation marks are used, for example,-I "E:/program files/Microsoft Visual C ++/vc98/indlue ". Here we select-I to help us set the settings, and then click "Next:
Figure 4.9 select whether to set the directory containing files
In this step, you can manually enter the file inclusion path in the text box below, use the Semicolon ";" or use Ctrl + enter to break multiple inclusion paths, or click brows, select directly in the directory tree. After entering the information, click "Next:
Figure 4.10 indicates that std_x.lnt has been created.
Because "Create a new STD. the following dialog box is displayed, indicating std_x.lnt, STD. LNT has been created in the configuration path. Here std_a.lnt actually contains STD. in addition to the LNT information, we also select the path and library configuration information. Click OK to continue:
Figure 4.11 shows whether to create a configuration file for other compiling Environments
After "OK" is selected, the system prompts whether to create a configuration file for other compilation environments. If "yes" is selected, a new configuration file will be created from step 4. Here we select "no ":
Figure 4.12 Replace the STD. LNT File
Next, you will be prompted whether to use the generated std_x.lnt file to replace the STD. LNT file. If "yes" is selected, the content of the std_x.lnt file will overwrite the content of the STD. LNT file, making the currently created configuration option the default configuration when creating a new configuration file. Generally, we choose "no" to continue the next step:
Figure 4.13 generate the global code check option file options. LNT
Next, you will prepare an option file that controls the display of global compilation information, options. LNT: The file is generated in two ways. One is that the installer explains several core options one by one and asks if you want to cancel the option. If you choose to cancel the option, it will be reflected in options. in the LNT file, the specific embodiment is to add-E before the information encoding, followed by a series of core selection processes. If you select the second option, the installation file will generate an empty options. LNT file, and you will add the necessary options in the future. Select the "no" option here, that is, do not cancel these options, and then click "Next ":
Figure 4.14 select the supported integrated development environment
Then select the supported integrated development environment options. You can select either one or more options. PC-Lint provides the function of integrating multiple development environments, for example, it can be integrated into VC, BC, and source insight. Here we select microsift visual c ++ 6.0 so that the env-v6.lnt will be copied to the configuration path. Click "Next ":
Figure 4.15 how to use the Lin. BAT file
The installer generates a Lin. BAT file, which is a batch file running PC-lint. To enable the file to run in any path, the installer provides two methods for you to choose from. The first method is to let you copy Lin. BAT to any path directory. The second method is to generate an lset. BAT file, run it to set the path each time before using the PC-LINT, or copy the content of the lset. BAT file to the autoexec. BAT file. We recommend that you select the first method. The specified directory is the installation directory of the current PC-lint. Select the first method: "Copy Lin. BAT to one of my path directory", and then click "Next" to enter the path directory:
Figure 4.16 specify the path directory
Enter the installation directory c:/pclint8 as the path directory, and click "Next" to enter the final confirmation window:
Figure 4.17 confirm configuration completion
Now the installation and configuration of PC-Lint have been completed. Click "finish" to use PC-lint. Multiple * generated under the configuration path during the above configuration process *. LNT file, except STD. LNT, std_x.lnt, and option. LNT is generated by the Configuration Wizard, other co-xxx.lnt, lib-xxx.lnt, env-xxx. LNT is copied from the original installation directory. In this directory, there are other compilers, libraries, and LNT configuration files supported by pclint, all LNT files are text files.
The above configuration method is suitable for the use of PC-lint at the beginning, for skilled users can directly edit, write each *. the LNT configuration file can work with the above configuration, or customize a configuration environment that is more suitable for your use.
2 PC-Lint integration with common development tools
The use of PC-Lint is very simple. You can use the command line method or integrate it into the development environment. The following describes the usage of PC-lint.
2.1 use command line
The command line is the most basic use method of PC-lint and the basis of other integrated use methods. You can use the command line to complete all the code analysis work of PC-lint. The command line of PC-Lint has the following forms:
Lint-NT Option file1 [file1 file3…]
Among them, lint-nt is the executable program lint-nt.exe of PC-lint on Windows NT/2000/XP platform. It completes the basic functions of PC-lint. Option represents various options acceptable to PC-lint, this is the most complex part of PC-lint. It has more than 300 options, which can be divided: the third part of this article has already introduced the options such as "forbidden option", "variable type Size Option", "redundant information option", "flag option", "output format option", and other options; file is the source file to be checked.
In addition, you can add the aforementioned *. the LNT configuration file name can be viewed as an extension of the command line. The various options and file lists configured in it have the same effect as those written in the command line.
2.2 integration of PC-lint and Visual C ++ integrated development environment (IDE)
In all integrated development environments, PC-Lint 8.0 provides the most comprehensive support for VC ++ 6 and VC ++ 7.0, it even supports project files directly from VC (vc6 is *. DSP, vc7 is *. vcproj) export the corresponding project. LNT file. This file contains the precompiled macro in the project settings. The header file contains the path and source file name. You do not need to manually write the project. LNT file.
The integration of PC-lint and VC is to add several custom commands in the integrated development environment of VC. The method for adding custom commands is to select "mimize" of "Tools... "command, select the" Tools "tab in the pop-up customize window, and add the custom command in the tab of the custom tool command. First, you must add a function for exporting the. LNT configuration file of the current project to the integrated development environment of VC. The command line for exporting the. LNT file is:
Lint-nt.exe + linebuf $ (targetname). DSP> $ (targetname). LNT
The parameter + linebuf indicates the size of the double row buffer, initially 600 bytes. The row buffer is used to store the information of the current row and the longest row you read. $ (Targetname) is the environment variable of the VC integrated development environment. It indicates the name of the currently activated Project. Check the "use output window" option, in this way, the PC-Lint will output the information to the output window. The result 4.18 is displayed:
Figure 4.18 add custom commands for exporting the project. LNT File
Then add a custom command to check the current file and check the Command Behavior of the file:
Lint-nt.exe-I "C:/pclint8"-u std_g.lnt env-vc6.lnt "$ (filename) $ (fileext )"
The first parameter-I "C:/pclint8" is the directory of the PC-Lint search *. LNT file. Here is the configuration path. Std_g.lnt is a configuration file customized for the VC compiling environment. $ (filename) and $ (fileext) are the environment variables of the VC integrated development environment. "$ (filename) $ (fileext) "indicates the file name of the current file. Like the export. LNT command, this command also needs to use the output window of the VC integrated environment to output the check information, so select the "use output window" option, as shown in 4.19:
Figure 4.19 Add a custom command to check the current file
Finally, you need to add a custom command to check the entire project. The command line to check the entire project is:
Lint-nt.exe + FFN-I "C:/pclint8" std_g.lnt env-vc6.lnt $ (targetname). LNT> $ (targetname). Chk
The result of this command is to output the check result of the entire project to the. Chk file with the same name as the project. In the parameter, + FFN indicates full file names, which can be used to control whether the full path name is used.
The following is a simple example to describe how to use PC-lint in the VC integrated development environment. First, create a simple project of the "Win32 console application" type (output "Hello World"), and add the example code referenced in Chapter 2 of this article to the project code, finally, manually add the include directory that this project code relies on to the configuration file, because the code check requires searching for stdafx. h: The pre-compiled file. Therefore, in this example, you must manually add the directory where the project code is located. The configuration file generated in this example is std_g.lnt. Open std_g.lnt in a text file and add a line to the file:
-Ic:/unzipped/test
"C:/unzipped/test" is the directory where the example project is located (stdafx. H is in this directory ). If your project is large and there are many header files containing directories, you need to add these directories to the configuration file one by one. After you make sure that there is no error in the code input (it does not matter if there is an error page, PC-Lint will check the error), you can start the code check. Example project: Open the code file to be checked. In this example, test. CPP, and then select the "pc_lint 8.0 check current file" command under the "Tools" menu. The output window outputs the check results for this file, as shown in 4.20:
Figure 4.20 check results
2.3 integration of PC-lint and source insight
The integration of PC-lint and source insight is also implemented by adding custom commands. Select the custom commands command item from the Options menu. Click "Add ..." As shown in figure 4.21, complete the following input in the pop-up "m commands" window:
Enter "PC-Lint check current file" in the name column. In principle, this name can be used as long as you can understand its meaning;
In the run column, enter "C:/pclint/lint-NT-u-ic:/pclint/lint std_f env-Si % F", where C: /pclint is the installation directory of your PC-LINT, std_f represents the configuration file std_f.lnt customized for source insight;
Select "iconic window" and "Capture output" in the output column;
Select "save files first" in the control column ";
In the source links in output column, select "parse links in output", "file, then line ";
In the pattern column, enter "^/([^] */)/([0-9] + /)";
Figure 4.21 add custom commands in source insight
After the command is added, you can click the "run" button to perform a PC-Lint check on the current file. For ease of use, you can also click "menu..." to add this custom command to the menu of source insight.
2.4 integration of PC-lint and ultraedit
The method of integrating PC-lint in ultraedit is similar to that of source insight. You can also add a custom command menu by clicking the "tool configuration" command in the "advanced" menu of ultraedit, 4.22. Enter the following content in the configuration window:
In the "menu project name" field, enter "PC-Lint check current file ";
In the "command line" column, enter the following command: C:/pclint/lint-NT-u-ic:/pclint STD env-Si % F, where C: /pclint is the installation directory of PC-lint, Using STD. the configuration in LNT is similar to that in the source insightde check environment, so the environment configuration in env-Si is used;
In the "working directory" column, enter the following path: e:/code, which is the directory where the code is located;
Select "Save all files first;
In the "command output" column, select "output to list" and "Capture output;
Click "insert" to insert the command line to the ultraedit menu;
Figure 4.22 add custom commands in ultraedit
At this time, a "PC-Lint check current file" menu will be added to the "advanced" menu of ultraedit. Click this menu to perform a PC-Lint check on the current file.
Summary
Software Debugging is a major factor in the development cost and delay of software projects. PC-Lint can help you find coding errors before dynamic testing of the program and reduce the cost of eliminating software errors. With PC-lint, you can check code before code reading and unit testing. You can detect program hidden errors in advance, improve code quality, and save test time. In addition, the use of PC-Lint encoding rules check can effectively regulate the coding behavior of software personnel. If you can effectively use the PC-Lint code check tool during software development, it will greatly improve the code quality and reduce software costs.
References
[1] gimpel software. Reference Manual for PC-Lint/flexelint. July, 2001
[2] explanation of PC-Lint options
From: http://www.360doc.com/content/10/0323/15/610539_19931453.shtml