How to include external library in kernel?

Hello. In kernel i’m adding this code


Then i need to add path of this file in host
In C it will be look like this -

clBuildProgram(cpProgram, 0, NULL, "-I C:/Users/localcontrol/internship/OpenCV/cv/include", NULL, NULL);

But in C++ i have this code

std::ifstream sourceFile(name);
	std::string sourceCode(
	Program::Sources source(1, std::make_pair(sourceCode.c_str(), sourceCode.length() + 1));

	// Make program of the source code in the context
	Program program = Program(context, source);

	// Build program for these specific devices

	errcode =;

And how to add path of my extern library?
I’m using AMD RX Vega 64

Based on OpenCL 1.2 specification (also the same for 2.0),

-I dir Add the directory dir to the list of directories to be searched for header files.

You cannot include any “.cl” into another “.cl”, but you can #include “Header.h” as much as you want where you can define some functions or define, etc.

Note that the code in those header must be in OpenCL C similar to your kernel (except if using OpenCL 2.2, where you can use OpenCL C++).

And lastly, except if you use OpenCL 2.0 and greater, you can’t call kernel function inside a kernel, so they must be ordinary function void foo().

So in your case, you could do this:

Program program = Program(context, source);
errcode =, "-I C:\Path\To\My\Include\Header);