clBuildProgram Problem and solution

The issue is that when you have a mistake in your #define generated code, the clBuildProgram returns (1) and clGetProgramBuildInfo gives absolutely no information about that mistake.

The code which would trigger this error:

The problem was that I did not have the right memory space chosen for Picture in GetPix function, after writing code without #defines, clBuildProgram returned right error with all the information, gathered by clGetProgramBuildInfo procedure. (BTW: clGetProgramBuildInfo returns only the source code when clBuildProgram returns 1)

IMHO issue is inside #defines, when a line with #define code has an error, then OpenCL Builder has issues finding the line with an error and it returns nothing.


  1. Try not to use #defines for error information, then correct mistakes and the code will build perfectly with no mistakes in #defines

  2. Check if code string is NULL-terminated © jcornwall

Could a moderator change topic name to “clBuildProgram returns 1”? I’ve forgotten about that.

It seems that this opencl call can return 1 in other case where source is invalid (without #define).
For sure it’s not a valid return value :).

I had 1 returned from clBuildProgram the other day when I fed it a string with no NULL terminator (sometimes running into a \0 off the end of the buffer, sometimes not).

I think it’d be great to collect here all the information about it returning 1, so that both nvidia and OpenCL developers could use it when then run into that error number.

In my opinion, it always returns 1 when it finds an error that was not implemented yet or predicted for Build (something like “switch…case” without the right value, I mean).


nVidia’s OpenCL compiler showing strange behavior on my Laptop having Core2Duo with nVidia Geforce 9600M GT and running Fedora 10. If .cl file content is modified slightly (even by adding a few spaces), the compiler fails to build the program (clBuildProgram return 1). Some other trivial modification again builds the program. Can anybody help?

yes i had this same error too=> clBuildProgram returns 1

and i was using one of the cl’s from the sdk example in my code. But i was not using that junk oclLoadProgSource function to load the file into a char buffer, i was using my own fileloader using fstream.
So the problem was it was opening the cl file using ios::in flag. This causes clBuildProgram return 1.

so those of you who are using your custom fstream file loaders can try this.
use ios::in|ios::binary flags, problem solved.