Search code examples
objective-coclint

oclint 0.8 on Ubuntu getting it to work


I'm a newb to oclint trying to get version 0.8 working on Ubuntu 14.04 desktop running as a VM in Virtualbox. I've built from the source rather than use the binaries.

I have 2 very simple programs. The first is a small cpp program that I compile:

gcc sample.cpp -o sample

I run oclint like this

oclint sample.cpp -- -c

And I get a text report.

I have another objective-c program that looks like this

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

        NSLog (@"hello world");
        [pool drain];
        return 0;
}

Compiled like so:

 gcc -c hello.m `gnustep-config --objc-flags` -lobjc -lgnustep-base

And this results in a working executable. But when I run against lint like this, I get a problem

 oclint hello.m -- -c 

Compiler Errors:
(please be aware that these errors will prevent OCLint from analyzing this source code)

/usr/include/x86_64-linux-gnu/sys/param.h:23:10: 'stddef.h' file not found


OCLint Report

Summary: TotalFiles=0 FilesWithViolations=0 P1=0 P2=0 P3=0 


[OCLint (http://oclint.org) v0.8.1]

I've installed a number of libraries to resolve the missing stddef.h file, inluding libc6 and libc6-dev with no success. I'm beginning to think that it's something in the way the oclint is run but I'm too new to figure it out quickly. I want to get the simple examples working before moving on to more complex ones.


Solution

  • I'm answering my own question. There are several issues with oclint, perhaps I didn't know them well enough.

    First of all it's important to get the command options right when running oclint. Best advice is to use bear when running the build to capture these options in a compile_commands.json file and use oclint-json-compilation-database to run oclint for you.

    oclint-json-compilation-database is a python script that you really need to look at before using. For example:

    #!/usr/bin/env python
    

    should be the location of python in your envrionment. I changed it to

    #!/usr/bin/python
    

    This python script reads compile_commands.json and formats a oclint command line call for every program that passes the filters. In my case the generated command line was too long and I was getting a seg. fault. When I shrank the command line down I got a valid run.

    All my problems are resolved. A little more improvement in the oclint docs would help.