With “Eclipse and PC-lint: Linticator” I have a plugin to lint my sources in a comfortable way. But I can do this as well without a plugin. For this I use a batch file with a build configuration, plus settings to get the PC-lint messages into the Problems view. Yes, this does not sound easy, but is very doable and straight forward once I have set it up. It gives me complete control on every little detail. Here is how I do it… PC-lint is like any other compiler: it compiles my source files. But, it is not producing object code: it is producing messages. So I need to set up the compiler to compile my sources, and to produce the messages so I can click and jump to the offending source files and lines. To run PC-lint with a project in eclipse means solving three problems:
- How to set up PC-lint as compiler for my project?
- How to pass options to the PC-lint compiler?
- How to configure the messages for the Problems view?
I’m using a joint approach with eclipse build configuration, batch file and lint option files. The solution presented here is using the following steps:
- Using a managed make build configuration
- Setting up a batch file to call PC-lint
- Defining the list of files
- Specifying the options
- Defining the message format
- Lint it!
Step 1: Build Configuration
To my existing project I add a managed make build configuration for PC-lint. The build configuration is set up to call a batch file. I select the project and use the menu Project > Build Configuration > Manage… and create a new configuration using the New button:
For the new configuration, I copy the settings from the existing configuration:
This new configuration would just use my normal compiler. Instead, I want to use the lint compiler. In Project > Properties > C/C++ Build > Builder Settings, I disable ‘Use default build command‘ and use instead:
${ProjDirPath}\lint\do_lint.bat "${ProjDirPath}" "${MCUToolsBaseDir}"
I’m pointing to a do_lint.bat
file inside a lint folder of my project which I will create in the next step. Additionally I disable ‘Generate Makefiles automatically‘:
CodeWarrior for MCU10.2 uses parallel builds by default. This would add -j6 as option to the command line. In order to disable this, I configure project specific settings in the Build Behaviour tab:
Step 2: Batch file
To separate the lint files from the rest of my build and project, I create a lint
sub-folder inside my project root with a do_lint.bat
batch file:
The do_lint.bat
has following content:
@rem The arguments for this batch file: @rem %1: The path to the project folder @rem %2: The path to the CodeWarrior installation folder @rem ------------------------------------------------------ @rem Path to my project folder SET PROJ_PATH=%1 @rem Path to CodeWarrior installation folder (which is e.g. "C:\Freescale\CW MCU v10.2\eclipse\..\MCU") SET CW_PATH=%2 @rem Path to lint-nt.exe SET LINT_EXE=C:\lint\lint-nt.exe @rem Path to my lint configuration files SET LOCAL_LNT_FILES=C:\Freescale\PC-lint\fsl_lnt @rem Path to my local lint folder inside the project SET PROJ_LINT_PATH=%PROJ_PATH%\lint @rem Lint configuration files and includes SET LNT_INCLUDES=-i"%LOCAL_LNT_FILES%" "%LOCAL_LNT_FILES%\co-mwhc08.lnt" -i%LOCAL_LNT_FILES% @rem --------------- Run PC-lint --------------------------- %LINT_EXE% %LNT_INCLUDES% %PROJ_LINT_PATH%\proj_options.lnt %PROJ_LINT_PATH%\proj_files.lnt -vf
The batch file is called from eclipse with two arguments (%1
and %2
): with the path to the project folder and the path to the CodeWarrior installation folder. I assign them to local variables (PROJ_PATH
and CW_PATH
) so I can use them inside the .lnt files. To know where my lint compiler is, I use LINT_EXE
. I store my lint configuration files outside of the PC-lint installation folder, that’s why I have defined a path variable for this: LOCAL_LINT_FILES
. PROJ_LINT_PATH
contains the project sub-folder with all my batch and lint files for the project. In LNT_INCLUDES
I specify my compiler lint configuration file, plus where lint shall search for my lint configuration files. Finally it calls the lint executable with the lint include files, plus two files: the project options (proj_options.lnt) and the project files (proj_files.lnt). I explain these files in Step 4.
Step 3: List of Files
I have created a file proj_files.lnt
file inside my project:
This file has all my source files listed. And because I have defined environment variables like PROJ_PATH
, I can use it here:
%PROJ_PATH%\Sources\main.c %PROJ_PATH%\Sources\Events.c
Step 4: Passing the options
What is missing are the project specific options: I add them to the proj_options.lnt
file:
In this file I add with the -i PC-lint option all the paths where it can find my files:
// Include paths used -i%PROJ_PATH% -i%PROJ_PATH%\Sources -i%PROJ_PATH%\Generated_Code -i%CW_PATH%\lib\hc08c\include
Additionally I specify all the global options, e.g. to inhibit messages:
// inhibit messages for Processor Expert libraries -elib(19, 10) -e766 +libh(Events.h, Cpu.h)
Step 5: Defining the message format
Last but not least: I need to tell PC-lint how to format the messages so they end up properly in the eclipse Problems view. I add them as well to the proj_options.lnt
:
// Coerce messages for Eclipse -hF1 +ffn // Normally my format is defined as follows: //-"format=%(\q%f\q %l %C%) %t %n: %m" // For eclipse-usage, the GCC error format is necessary, // since we have only the default eclipse error parser available. -"format=%(%f:%l:%C:%) %t %n: %m" // Enable warning 831 if you are interested. -frl // Do not break lines -width(0) // And make sure no foreign includes change the format +flm
Update: Use the following as message format option and things will show up properly with message type in Eclipse:
-“format=%(%f:%l:%C:%) %t: %n: %m”
Step 5: Linting in action
Time to see how this works! As I have set up a separate build configuration to lint my files, I can run it like any other build configuration:
The example below shows several lint errors for main.c. The messages show up in the Problems view, and are listed as well in the Console view:
Summary
The approach presented here does not need any other eclipse plugin. It is using a batch file, and uses a brute force approach: it will lint all files regardless if they have changed or not. This could be improved with a make file approach as outlined here. The approach presented here requires some setup, is pretty simple, and routes all lint messages to the Problems view. If I want to use more of a plugin approach, then the Linticator plugin is the alternative.
Thanks to Catherine for providing a lot of good ideas used in this article!
Happy linting 🙂
Thanks man, this was a life saver!
LikeLike
Hi John,
thanks for reading, and glad to hear that it was useful for you 🙂
Erich
LikeLike
Pingback: FreeRTOS V7.5.0 released | MCU on Eclipse
Pingback: Linting with Eclipse and the GNU ARM Embedded Launchpad Compiler | MCU on Eclipse
Thanks bro, you totaly saved me (and a lot of my friends) from that Linticato plugin!
LikeLike
If you add a colon after %t (-“format=%(%f:%l:%C:%) %t: %n: %m”) Eclipse even detects the type (info/warning/error) and marks the code accordingly.
LikeLike
Hi Michael,
thank you, that indeed helps to show the proper message format!
Erich
LikeLike
This article has been really helpful. Works really well and so much easier to use than cmd prompt. Many thanks for taking the time to share this.
LikeLike
thank you :-), and you are welcome!
LikeLike
Thank you very much for your kind sharing!
I copied your way to integrate PC-lint tools into Eclipse, actually Code Composer Studio v8.3.1, which is an eclipse-based developing tool provided by Texas Instruments for DSP devices.
I tried linting a single c-file instead of directly a whole project in the first place. I adjusted some commands. It seemed great that I got the linting results, but the results didn’t appear in the Problems view, and the results in Console view had no linkage to code-lines where produced those warnings and errors.
Could you please analyze what would be the cause?
I have used Linticator in recent days with a trial license, it does provide linkages to warning and error lines in both Problems view and Console view.
LikeLike
The linkage between Eclipse problems view and the Lint output is the message format:
Eclipse tries to parse the output format, and if the messages do not match, it will not able to display them.
I do have a similar article here:
https://mcuoneclipse.com/2015/12/13/linting-with-eclipse-and-the-gnu-arm-embedded-launchpad-compiler/
See for example:
// Normally my format is defined as follows:
//-“;format=%(\q%f\q %l %C%) %t %n: %m”;
// For eclipse-usage, the GCC error format is necessary,
// since we have only the default eclipse error parser available.
-“;format=%(%f:%l:%C:%) %t: [%n] %m”;
I hope this helps,
Erich
LikeLike
If your -“format=%(%f:%l:%C:%) %t: %n: %m” line gives you errors, just replace the double quotes with ” (straight) type quotes instead of “ (skew) type
LikeLiked by 1 person
Yes, indeed: one needs to be careful with copy of text from somewhere, including PDF: typographic double-quotes have been an issue all the time. Good point, and thanks for reminding on that one.
LikeLike
When I make do_lint.bat file the windows cant really give me opportunity to open it…because it says cant run on pc .. it there any solution to that problem ??
LikeLiked by 1 person
you can call the batch file from a command prompt too. Check your build command settings, you probably have not configured it properly.
LikeLike