foreword
Dependent tools:
1. cppcheck tool
2. Install C/C++ Advanced Lint extension under vscode
3. python tool
1. Download and install cppcheck
1. Download the cppcheck tool installation package: http://cppcheck.net/
2. Double-click the installation package:
After double-clicking, the software will install itself in: C:\Program Files\Cppcheck
3. Add the cppcheck system path:
4. Download the source code of cppcheck: Github official website download link
5. Copy the "addons" folder in the downloaded cppcheck source code to the cppcheck tool installation directory C:\Program Files\Cppcheck
2. Install C/C++ Advanced Lint extension under vscode
1. Under the vscode software, search for C/C++ Advanced Lint on the extension page and install it
2. Configure the C/C++ Advanced Lint extension
2.1. Click the Settings button in the vscode software and select the "Settings" option
2.2. Search for "@ext:jbenden.c-cpp-flylint" and edit in "settings.json"
2.3. Add these lines in settings.json to disable flexelint, lizard, flawfinder, and clang, the four lines of code inspection tools, or uncheck these options on the page
"c-cpp-flylint.clang.enable": false,
"c-cpp-flylint.flexelint.enable": false,
"c-cpp-flylint.lizard.enable": false,
"c-cpp-flylint.flawfinder.enable": false,
After saving, you can see that there is a verification of cppcheck itself below
2.4. Add the configuration of MISRA-C rules, configure the addon of Cppcheck as misra, and then save
2.5. Add the MISRA_C_2012.txt file under the root directory of the C drive. This file is the misra 2012 verification rule. This file can be downloaded from the Internet
2.6. After adding this file, if you want to see the specific misra error prompt, you need to create a misra.json file and write the following content:
Note: The file path in the "args" parameter is the path of the c disk where the MISRA_C_2012.txt file is stored in step 2.5; the
misra.json file can be placed under a path you like, but like the MISRA_C_2012.txt file, do not put it under the path of c:\Program Files\ (try not to install the development software under the path of Program Files, there will be inexplicable problems), this experiment Put these two files in the root directory of the c drive:
2.7. Here, because of the experiment, a test file test.c is created
Three, python installation
1. Download python from the official website: python official website
2. During the experiment, 3.8.5 was selected, and the latest version should also work:
3. Double-click the downloaded installation package: python-3.8.5-amd64.exe, check add to add the python path option, and then click "install now"
If checked, the step of adding environment variables is omitted
3. Win + R to open the dos window or click the small search icon on the taskbar to open the search "cmd" to open the command prompt
4. Enter "python" to see the version, which means the installation is successful
5. Enter the path to store the code file in the dos window:
6. Enter cppcheck --dump test.c:
You can see the code errors detected by cppchek
7. Enter the following command:
python “c:\ProgramFiles\Cppcheck\addons\misra.py” --rule-texts=MISRA_C_2012.txt test.c.dump
Note: The content in double quotes is the python script that performs the detection; – the following is the misra 2012 rule
The rule was executed successfully in the misra.py script
8. Go back to the bottom of vscode, you can see the grammatical error under the test file, you can also create other files, and you can see the specific reason for the error
Note: If you are not familiar with the English prompt, you can check it against each rule in the MISRA_C_2012.txt file. There is also a Chinese interpretation of the rule on the Internet.