Linting without a plugin

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:

  1. How to set up PC-lint as compiler for my project?
  2. How to pass options to the PC-lint compiler?
  3. 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:

  1. Using a managed make build configuration
  2. Setting up a batch file to call PC-lint
  3. Defining the list of files
  4. Specifying the options
  5. Defining the message format
  6. 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:

Creating new build configuration

Creating new build configuration

For the new configuration, I copy the settings from the existing configuration:

Creating new configuration

Creating new 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‘:

Builder Settings for PC-lint batch file

Builder Settings for PC-lint batch file

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:

Custom Build Behaviour

Custom Build Behaviour

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:

do_lint batch file

do_lint 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
@rem Path to CodeWarrior installation folder (which is e.g. "C:\Freescale\CW MCU v10.2\eclipse\..\MCU")
@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
@rem Lint configuration files and includes
@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:

File listing the files to lint

File listing the files to lint

This file has all my source files listed. And because I have defined environment variables like PROJ_PATH, I can use it here:


Step 4: Passing the options

What is missing are the project specific options: I add them to the proj_options.lnt file:

Project Options File

Project Options File

In this file I add with the -i PC-lint option all the paths where it can find my files:

// Include paths used

Additionally I specify all the global options, e.g. to inhibit messages:

// inhibit messages for Processor Expert libraries
-elib(19, 10)
+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
// 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.
// Do not break lines
// And make sure no foreign includes change the format

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:

Build my lint configuration

Build my lint 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:

Linting in action

Linting in action


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 ๐Ÿ™‚

4 thoughts on “Linting without a plugin

  1. Pingback: FreeRTOS V7.5.0 released | MCU on Eclipse

  2. Pingback: Linting with Eclipse and the GNU ARM Embedded Launchpad Compiler | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s