This is a followup to Using #include to load OpenCL code
I've noticed that when you use the method described by grrussel (and used in Bullet Physics), the created string has all newlines stripped (comments seem to be stripped, too, but I'm not too worried about that). Now for the most part this is fine if the included opencl code doesn't have any preprocessor definitions in it, but if there is the code will fail to compile with the OpenCL compiler.
Is there a way to get the #include
to keep the newlines in there, or is there a better method to embed the opencl code into my executable (other than copying the string into a cpp file and putting quotes around everything)?
I tested this in Visual Studio 2010, I'm not sure if other compilers exhibit the same behavior. I would prefer a method which doesn't require any external tools and works with a variety of compilers/platforms.
Copied code from other answer:
In C++ / C source
#define MSTRINGIFY(A) #A
char* stringifiedSourceCL =
#include "VectorAddKernels.cl"
In the OpenCL source
MSTRINGIFY(
__kernel void VectorAdd(__global float8* c)
{
// snipped out OpenCL code...
return;
}
);