including header files to opencl

Hey guys,

I wondered how to include a standard c header file into my cl file. If I try this, the compiler throws an error with the message: “Cannot find header file” although I put the header file in the same directory as the cl file. How can I access existing header files from my opencl file?


You don’t include using the standard “#include” syntax. When you call clCreateProgramWithSource pass the additional header file in. Note, the strings argument takes multiple strings. I’ve also found the order you specify the multiple strings of data matters.

Also, I prefer the C++ bindings, it makes this kind of thing a tad easier:

ok, but I’m now using oclLoadProgSource() to get my source string and pass it as the string parameter of the clCreateProgramWithSource function. how do i add additional header files to that string? is this possible?


You can pass an include directory and use #include.

Mind using spaces in your path, or use my solution in a windows environment


Hi guys,

 I stumbled on this post during a Google search and I wanted to ask a question.  When I do a clBuildProgram command, I get no feedback about any errors during compilation.  How do you get meaningful errors returned?  Thanks in advance for your help.

You can use clGetProgramBuildInfo(). I don’t have the specs at hand, but if you look at the Khronos spec, you will find how to use it. Basically, it takes a string buffer and writes the error message into it.