OpenCL log file locates errors as if the code was a single long line

I produce a log file (with OpenCL on OSX) doing

void printErrors(const Program& program, const Device& device){
    string buildlog = program.getBuildInfo<CL_PROGRAM_BUILD_LOG>(device);
    ofstream file("./error.txt");
    file << buildlog << endl;
    file.close();
}

But the resulting file seems to interpret the code as a single VERY long line. For example, an error is located as <program source>:1:10604:. Which is not very convenient for debugging. Do you know how to get a good location like <program source>:line:column: ?

By the way, for each error/warning the entire program is copied in the log file. Do you know how to avoid this behavior ?

The source code is generated this way:

ifstream file("./kernel.cl");

string source;

while (!file.eof()){
    char line[256];
    file.getline(line, 255);
    source += line;
}

const char* kernel_source = source.c_str();

program = Program(context, kernel_source);

int result = program.build(device);
if (result == CL_BUILD_PROGRAM_FAILURE) printErrors(program, device);

And the file kernel.cl is really standard with semicolon at the end of each line.

Answer

I think your issue is here:

char line[256];
file.getline(line, 255);
source += line;

getline will not include newline characters, so you will need to insert them explicitly. Try this:

source += line;
source += "n";

This should also solve the issue of the entire source-on-one-line being included in the error message.

Leave a Reply

Your email address will not be published. Required fields are marked *