views:

37

answers:

1

I am trying to include the following kernel routine into my Cocoa / objective C project. But I'm getting a compiler error when I build the project. The very first line is flagged with a syntax error saying "expected '=', ',', ';', 'asm' or 'attribute' before 'vec4'.

Any ideas what this means and how to resolve it? As far as I can tell, the declaration looks pretty much just like all the other kernel samples I can find.

kernel vec4 threshold(sampler image, float midPoint, float range ) // First error on this line
//This from http://www.codingadventures.com/2008/06/threshold-filter-in-glsl/
{
    vec4 pixel=unpremultiply( sample(image, samplerCoord(image)) );

    float high = midPoint + range * 0.5;
    float low = midPoint - range * 0.5; 

    high = min(1.0, high);
    low = max(0.0, low);

    float brightness = 0.3 * pixel.x + 0.59 * pixel.y+ 0.11 *pixel.z;

    brightness = step( low, brightness ) * brightness;

    brightness = brightness + step(  high, brightness );
    brightness = min( 1.0, brightness );

    pixel.x = pixel.y =pixel.z = brightness;

    return premultiply(pixel);
}
+1  A: 

You're missing a framework import. The error is that the compiler doesn't know what kernel means (it's expecting you to assign it a value or otherwise declare it).

Try following these steps:

  1. Choose Project > Add to Project.
  2. Navigate to System/Library/Frameworks, choose the QuartzCore.framework and click Add.
  3. In the sheet that appears, click Add.

And then you may need to additionally #import <QuartzCore/QuartzCore.h> in all the files you wish to use Core Image.

Matt B.
Thanks for the reply, Matt. I do have the QuartzCore.framework in my project (under Frameworks / Linked Frameworks). And I added the #import statement into the .m module I am compiling. But I still have the same error ...Any other ideas?
Adam
@Adam: Perhaps try changing your compiler to Clang. It often has better error messages and may perhaps give you (or the rest of SO) a better clue as to what is going wrong.
Matt B.
There were three other choices for Compilers listed (assuming I am looking in the right spot -- Project Info / Compiler Version): an earlier version of GCC and two variations of the LVMM compiler. I tried all of these and my compiler error did not change. I'm not sure if this means that they all return the exact same message ... or if for some reason my attempt to change the compiler was not working. There was no Clang listed. I tried just typing it into the "other" list. It let me do that, but this had no effect on the error message, either.
Adam
Thinking there might be some kind of non-printable character on line one (which I could not see but which was fouling up the compiler), I manually retyped the entire line. This had no effect on the compiler error...
Adam
@Adam: Ah, I think I was wrong on the framework you were missing. Try adding the OpenCL framework and add `#import <OpenCL/opencl.h>` to that file.
Matt B.
Just tried the OpenCL suggestions, too ... still no change in the compiler error.
Adam
@Adam: Shucks. The only place I can find `kernel` defined is in OpenCL's system headers, but I'm certain that the trouble is that `kernel` isn't getting defined certainly. I'm afraid I'm of no more help here. Best of luck.
Matt B.