Using PC Lint in Eclipse – no plug-ins required

I’ve been tinkering with Eclipse to see if I can make PC Lint run from inside Eclipse. Of course, running Lint as an external tool is always an option, but I couldn’t get Eclipse to recognize the Lint warnings and display them in the ‘Problems’ tab. From my testing and what I could find in the Internet, it seems that the output of so-configured external tools is not run by the error parsers installed.

What I found in the Internet suggested that I have to use a special error parser, configure that, and then it would run. Now, I have nothing against using extra tools if that’s the way to achieve what I want, but if I can do without, I consider that a better solution, since every tool used is another tool to learn how to use. And delivering configurations to my customers,  it’s not my business model to make myself indispensable, on the contrary.

So, after experimenting some more, I have found a way to use PC Lint with Eclipse (I used Ganymede for testing) without resorting to additional tools or plug-ins. Be aware, I’m not an Eclipse expert in any sense, so there may be many more and possibly better ways to achieve this. I’d be happy to get some comments with further tips.

The key is to add a new ‘build target’ for running PC Lint:

  1. On the properties dialog for the workspace (right-click and select ‘Properties’), in the ‘Builders’ section, check that the “CDT Builder” is selected.
  2. In the ‘C/C++ Build’ section, click on “Manage Configurations…” and add a configuration for running Lint.
  3. Select the configuration from the drop-down box.
  4. On the ‘Builder Settings’ tab, deselect the “Use default build command” and instead provide the path to the Lint executable, eg. “C:\Lint90\LINT-NT.EXE”. Specify the ‘Build location’, from which directory you want Lint to run, either absolute or using the buttons offered.
  5. On the ‘Behaviour’ tab, deselect “clean”, and provide the parameters to Lint in the (selected) ‘Build (Incremental build)’ text box.
  6. Be aware that these indications all assume some kind of a general build or make environment, so the names themselves do not indicate the possibility for running a single program. If you use a Makefile concept for running Lint, you may use that as well, and ‘clean’ might even make sense.

  7. In the ‘Settings’ section of ‘C/C++ Build’, make sure that all CDT parsers (or at least the “CDT GNU C/C++ Error Parser”) are selected.

And that’s it.

OK; one final thing remains. We now need to coerce Lint into providing warnings in a format similar to the GNU C/C++ compiler. This can be achieved by some Lint options in your option file. I use:

// Output options: One line, file info always; Use full path names

-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"

// And also for eclipse, the reference locations provided by

// Lint, put into square brackets “[Reference: File: ... Line: ...]”

// are not correctly handled, therefore we switch them off.

// Enable warning 831 if you are interested.

-frl

// Do not break lines

-width(0)

// And make sure no foreign includes change the format

+flm

If you want to know more than my comments are telling you, check the Lint manual for details.

Now, don’t get me wrong: I will not switch from my trusted SlickEdit to Eclipse. But, as a consultant, I cannot always pick and choose. And running Lint from Eclipse, having a way to jump from warning to warning, definitely beats manual navigation.

Happy Linting!

Tags: , ,


8 Responses to “Using PC Lint in Eclipse – no plug-ins required”

  1. KolbenJoe says:

    Great description!

    That’s what I was missing – I always tried fruitlessly with Lint as external tool and additional error parsers.
    Now I am able to lint a single file using the string ” -u ${selected_resource_loc}” in the workbench build behaviour.

    best regards,

    Thorsten

  2. nietfou says:

    Dear Johan,

    I tried to apply your hints to use PC-Lint in Eclipse. I’m not using the Ganymede version but the Galileo (In fact Altium Tasking running on Eclipse Galileo). I’m getting a strange behavior in the Build command field. There is always a -j option automatically added to the build command I’m entering. Did you also encounter this behavior with Ganymede? PC-Lint doesn’t support this -j option and stops executing.

    Any hint about this issue welcomed!

    Best regards.

    J-D

  3. nietfou says:

    I found the reason of the -j option always present. On the behaviour tab, “use parallel build” must be unchecked to remove the -j option.

    But now, when this is the build options provided in the Build(Incremental build) text field that are the problem. If using the -os(xxx) option, Eclipse complains because there are options after the ‘)’ character. If using the >xxx syntax to redirect output, error 72: bad option is mentionned. The options (-b loptions.lnt project.lnt temp.lnt files.lnt >lintout.tmp) are not the cause as they don’t make any problem when used when calling lint-nt from the command line.

    It seems a lot changed since Ganymede release. Where you not encountering such problems?

  4. nietfou says:

    I finally found a solution to avoid the Eclipse limitation in specifying options through the Buid(incremental build) text field.

    The way I choosed is to define the whole command line in a batch file and to reference this batch file instead of the lint-nt.exe.

  5. dobromy says:

    Good description!

    But unfortunately it didn’t help me to integrate PC-Lint into Code-Warrior V10.1 based on Eclipse. I did all the steps described above and it was possible to call lint-nt application as soon as I tried to biuld a project, but no files were passed as argument!

    What could be my mistake?

    BR.
    Peter

  6. Johan Bezem says:

    Sorry for the long response time, I’ll try to improve.
    What options did you provide in step 5?
    I don’t have eclipse running at the moment, but the options/parameters you have to provide in step 5 determine what parameters lint-nt.exe will see. It looks as if there’s a potential problem.
    If you have used my “How to wield PC Lint” document, the options could read something like
    loptions.lnt project.lnt temp.lnt -u ${selected_resource_loc}
    If that doesn’t help, please provide some more details of what you did.

    HTH,

    Johan

  7. Fetti says:

    Hello,

    I implemented the PC Lint Error Parser in my project.

    Here my configuration:
    - CDT GNU C/C++ Error Parser activated
    - following build incremental command: -hF1 +ffn -”format=%(%f:%l:%C:%) %t %n: %m” project.lnt ${selected_resource_loc} +flm

    The funny thing is, for some files, everything works fine. It is possible to jump to error using double click. But there are some other files which only present the error in the console?!

    What I am doing wrong?

    Thanks in advance.

    Andreas

  8. Johan Bezem says:

    Be aware that Lint has four categories of warnings: Error, Warning, Info and Note. Normally, all ‘Note’s are disabled, but ‘Info’s are enabled.
    Most filters will only allow ‘Error’ and ‘Warning’, you may have to add ‘Info’ and ‘Note’ to the appropriate regular expression.

    HTH,

    Johan


Leave a Reply

You must be logged in to post a comment.