title: Can I separate compile binary in opencl like this way?
body: <pre class="lang-c prettyprint-override"><code>    cl_program prog_cl;;
      cl_program pprogram_head;
      std::ifstream srcFile(&quot;kernel.cl&quot;);
      string srcProg(istreambuf_iterator&lt;char&gt;(srcFile), (istreambuf_iterator&lt;char&gt;()));
      const char* src = srcProg.c_str();
      size_t src_length = srcProg.length();
  
      prog_cl = clCreateProgramWithSource(context, 1, (const char**)&amp;src,
          &amp;src_length, &amp;err);
      err = clCompileProgram(prog_cl, 1, &amp;device, NULL, 0, NULL, NULL, NULL, NULL);
      std::cout &lt;&lt; &quot;  clCompileProgram1: &quot; &lt;&lt; err;;
      char* programBinary = new char[1024];
      FILE* pf;
      size_t programBinarySize;
      
      clGetProgramInfo(prog_cl, CL_PROGRAM_BINARY_SIZES, sizeof(cl_device_id), &amp;programBinarySize, NULL); 
      programBinary = ( char*)malloc(sizeof(unsigned char) * programBinarySize);
      clGetProgramInfo(prog_cl, CL_PROGRAM_BINARIES, sizeof(unsigned char*), &amp;programBinary, NULL);      
      
      fopen_s(&amp;pf, &quot;vec.bin&quot;, &quot;w&quot;);
      fwrite(programBinary, 1, programBinarySize, pf);
      free(programBinary);
      fclose(pf);
  
      programBinarySize = readSource(&quot;vec.bin&quot;, &amp;programBinary);
      cl_program prog[2];
  
      prog[0] = clCreateProgramWithBinary(context, 1, &amp;device, &amp;programBinarySize, (const unsigned char**)&amp;programBinary, NULL, &amp;err);
      std::cout &lt;&lt; &quot;clCreateProgramWithBinary&quot; &lt;&lt; err &lt;&lt; std::endl;
      err = clCompileProgram(prog[0], 1, &amp;device, NULL, 0, NULL, NULL, NULL, NULL);
  
      std::ifstream srcFile_head(&quot;add.cl&quot;);
      string srcProg_head(istreambuf_iterator&lt;char&gt;(srcFile_head), (istreambuf_iterator&lt;char&gt;()));
      const char* src_head = srcProg_head.c_str();
      size_t src_length_head = srcProg_head.length();
      prog[1] = clCreateProgramWithSource(context, 1, &amp;src_head, &amp;src_length_head, &amp;err);
      err = clCompileProgram(prog[1], 1, &amp;device,NULL, 0, NULL, NULL, NULL, NULL);
      std::cout &lt;&lt; &quot;clCompileProgramn3&quot; &lt;&lt; err;
  
      cl_program program = clLinkProgram(context, 1, &amp;device, NULL, 2, prog, NULL, NULL, &amp;err);
  </code></pre>
  <p>I always get cllinkprogram error.what is the right way to do this?I want compile a binary form disk.And Separate Compilation and Linking with clCompileProgram and clLinkProgram</p>