---
name: "clLinkProgram"
section: "3clc"
platform: "linux"
package: "opencl-1.2-man-doc"
version: "1.0~svn33624-5.1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/clLinkProgram"
---

# clLinkProgram(3clc)

Links a set of compiled program objects and libraries for all the devices or a specific device(s) in the OpenCL context and creates an executable.

## NAME

clLinkProgram - Links a set of compiled program objects and libraries for all the devices or a specific device(s) in the OpenCL context and creates an executable.

##

**cl\_program clLinkProgram(cl\_context** *context***, cl\_uint** *num\_devices***, const cl\_device\_id \****device\_list***, const char \****options***, cl\_uint** *num\_input\_programs***, const cl\_program \****input\_programs***, void** *(CL\_CALLBACK \*pfn\_notify) (cl\_program program, void \*user\_data)***, void \****user\_data***, cl\_int \****errcode\_ret***);**

## PARAMETERS

 *context*

Must be a valid OpenCL context.

 *device\_list*

A pointer to a list of devices that are in *context*. If *device\_list* is a NULL value, the link is performed for all devices associated with *context* for which a compiled object is available. If *device\_list* is a non-NULL value, the compile is performed for devices specified in this list for which a source has been loaded.

 *num\_devices*

The number of devices listed in *device\_list*.

 *options*

A pointer to a null-terminated string of characters that describes the link options to be used for building the program executable. See [**clBuildProgram**(3clc)](/clBuildProgram/3clc.md) for a list of supported compiler and linker options.

 *num\_input\_programs*

Specifies the number of programs in array referenced by *input\_programs*.

 *input\_programs*

An array of program objects that are compiled binaries or libraries that are to be linked to create the program executable. For each device in *device\_list* or if *device\_list* is NULL the list of devices associated with *context*, the following cases occur:

• All programs specified by *input\_programs* contain a compiled binary or library for the device. In this case, a link is performed to generate a program executable for this device.

• None of the programs contain a compiled binary or library for that device. In this case, no link is performed and there will be no program executable generated for this device.

• All other cases will return a **CL\_INVALID\_OPERATION** error.

 *pfn\_notify*

A function pointer to a notification routine. The notification routine is a callback function that an application can register and which will be called when the program executable has been built (successfully or unsuccessfully).

If *pfn\_notify* is not NULL, **clLinkProgram** does not need to wait for the linker to complete and can return immediately once the linking operation can begin. Once the linker has completed, the *pfn\_notify* callback function is called which returns the program object returned by **clLinkProgram**. The application can query the link status and log for this program object. This callback function may be called asynchronously by the OpenCL implementation. It is the application’s responsibility to ensure that the callback function is thread-safe.

If *pfn\_notify* is NULL, **clLinkProgram** does not return until the linker has completed.

 *user\_data*

Will be passed as an argument when *pfn\_notify* is called. *user\_data* can be NULL.

## NOTES

**clLinkProgram** creates a new program object which contains this executable. The executable binary can be queried using [**clGetProgramInfo**(3clc)](/clGetProgramInfo/3clc.md)(program, **CL\_PROGRAM\_BINARIES**, ...) and can be specified to [**clCreateProgramWithBinary**(3clc)](/clCreateProgramWithBinary/3clc.md) to create a new program object.

The devices associated with the returned program object will be the list of devices specified by *device\_list* or if *device\_list* is NULL it will be the list of devices associated with *context*.

The linking operation can begin if the context, list of devices, input programs and linker options specified are all valid and appropriate host and device resources needed to perform the link are available. If the linking operation can begin, **clLinkProgram** returns a valid non-zero program object.

## ERRORS

If *pfn\_notify* is NULL, the *errcode\_ret* will be set to **CL\_SUCCESS** if the link operation was successful and **CL\_LINK\_FAILURE** if there is a failure to link the compiled binaries and/or libraries.

If *pfn\_notify* is not NULL, **clLinkProgram** does not have to wait until the linker to complete and can return **CL\_SUCCESS** in *errcode\_ret* if the linking operation can begin. The *pfn\_notify* callback function will return a **CL\_SUCCESS** or **CL\_LINK\_FAILURE** if the linking operation was successful or not.

Otherwise **clLinkProgram** returns a NULL program object with an appropriate error in *errcode\_ret*. The application should query the linker status of this program object to check if the link was successful or not. The list of errors that can be returned are:

• CL\_INVALID\_CONTEXT if *context* is not a valid context.

• CL\_INVALID\_VALUE if *device\_list* is NULL and *num\_devices* is greater than zero, or if *device\_list* is not NULL and *num\_devices* is zero.

• CL\_INVALID\_VALUE if *num\_input\_programs* is zero and *input\_programs* is NULL or if *num\_input\_programs* is zero and *input\_programs* is not NULL or if *num\_input\_programs* is not zero and *input\_programs* is NULL.

• CL\_INVALID\_PROGRAM if programs specified in *input\_programs* are not valid program objects.

• CL\_INVALID\_VALUE if *pfn\_notify* is NULL but user\_data is not NULL.

• CL\_INVALID\_DEVICE if OpenCL devices listed in *device\_list* are not in the list of devices associated with *context*.

• CL\_INVALID\_LINKER\_OPTIONS if the linker options specified by *options* are invalid

• CL\_INVALID\_OPERATION if the compilation or build of a program executable for any of the devices listed in *device\_list* by a previous call to [**clCompileProgram**(3clc)](/clCompileProgram/3clc.md) or [**clBuildProgram**(3clc)](/clBuildProgram/3clc.md) for program has not completed.

• CL\_INVALID\_OPERATION if the rules for devices containing compiled binaries or libraries as described in *input\_programs* argument above are not followed.

• CL\_LINKER\_NOT\_AVAILABLE if a linker is not available i.e. **CL\_DEVICE\_LINKER\_AVAILABLE** specified in the table of allowed values for *param\_name* for [**clGetDeviceInfo**(3clc)](/clGetDeviceInfo/3clc.md) is set to **CL\_FALSE**.

• CL\_LINK\_PROGRAM\_FAILURE if there is a failure to link the compiled binaries and/or libraries.

• CL\_OUT\_OF\_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device.

• CL\_OUT\_OF\_HOST\_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host.

## SPECIFICATION

**OpenCL Specification**\[1\]

## SEE ALSO

[**clGetDeviceInfo**(3clc)](/clGetDeviceInfo/3clc.md)

## AUTHORS

**The Khronos Group**

## COPYRIGHT

Copyright © 2007-2011 The Khronos Group Inc.\
 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.

## NOTES

- 1\.

  OpenCL Specification

  page 142, section 5.6.3 - Separate Compilation and Linking of Programs
