opencl API : include headers to .cl file


I wrote a kernel in a .cl file, but when I include a .h file, and run code,
I get ““file.h” not found”.
so I read the opencl spec, and found that I have to add the path to the headers to my buildprogram API (5.4.3 of 1.0spec), so this is my code line:

ciErrNum = clBuildProgram(cpProgram, 0, NULL, "-I C:/Users/localcontrol/internship/OpenCV/cv/include", NULL, NULL);

but it doesn’t work, the program crashes at this line,

is anyone seeing what could be the problem,
I really need help with this.

when you use clCreateProgramWithSource, you transfer your .cl file. You can do the same thing for .h file, assuming your .h is for .cl file. Just transfer them together.

I did what you said,
I included the .h file to clCreateProgramWithSource, just as source file, this is my code:

const char* clSourcefile = "";// source file
const char* cvincludefile = "cv.h"; //include file
 // Program Setup
	const char* strings[2];

    size_t program_length;
    const char* source_path = shrFindFilePath(clSourcefile, argv[0]);
    char *source = oclLoadProgSource(source_path, "", &program_length);
    shrCheckErrorEX(source != NULL, shrTRUE, pCleanup);

	size_t include_length;
    const char* include_path = shrFindFilePath(cvincludefile, argv[0]);
    char *cvinclude = oclLoadProgSource(include_path, "", &include_length);
    shrCheckErrorEX(cvinclude != NULL, shrTRUE, pCleanup);
	strings[0] = source;
	strings[1] = cvinclude;
	size_t lenghts[2];
	lenghts[0] = program_length;
	lenghts[1] = include_length;
    // create the program
	cpProgram = clCreateProgramWithSource(cxGPUContext, 2,(const char **) &strings, (const size_t *) &lenghts, &ciErrNum);
    shrCheckErrorEX(ciErrNum, CL_SUCCESS, pCleanup);

    // build the program
    ciErrNum = clBuildProgram(cpProgram, 0, NULL, NULL, NULL, NULL);
    if (ciErrNum != CL_SUCCESS)

But when I run it I got nothing in the build log, before adding the .h file, I was getting errors tha it doesn’t recognize
undefined variables (defined in .h file), now I get nothing.,
can you see if I maid an error in my code please.

I am not familiar with the class you use here for reading the files. But there must be something wrong when you do that. So what about, you just try to read a very simple .cl file. just to do some simple operation(not use variable you define in .h) to make sure the way of file reading is correct.

then you can proceed to the .h file part.

actually I copied this syntaxe from nvidia exemples from sdk, and it’s working fine to read .cl file
it’s working with my code too because I have errors returned from my .cl file
so it can read .cl file, when I add .h it returns a buildprogram error,
so I’m assuming it didn’t read the .h right
it’s very anoying, all this opencl syntaxe just to include a header

‘it’s working with my code too because I have errors returned from my .cl file’

this does not mean your code is good(you still can’t run your code). ‘you got error for .cl file’ != you successfully read the file for the building of program.

why don’t you just follow my suggestion to read a simple .cl file to test. do some simple operation, plus/minus, whatever you like

I did what you said,
the compiler is working fine,
actually it’s a problem with my code