Development

How to fix usrbinld cannot find -lOpenCL Error in Ubuntu

Captain Salem 1 min read

How to fix /usr/bin/ld: cannot find -lOpenCL Error in Ubuntu

OpenCL (Open Computing Language) is an open royalty-free standard for general purpose parallel programming across CPUs, GPUs and other processors, giving software developers portable and efficient access to the power of these heterogeneous processing platforms.

In some cases, you may come across a tool that requires the OpenCL library to run. If the OpenCL library is missing, you may get the /usr/bin/ld: cannot find -lOpenCL error when compiling the tool.

This very short post, we will give you a simple and quick method of fixing this error on your Ubuntu and Debian based systems.

What causes this error?

As mentioned, this error occurs when the libraries such as OpenCL which are needed to successfully compile and use the program are not found.

In this case, the linker tells you that it cannot find the OpenCL library on your system.

Solution

To fix this error, start by installing the OpenCL library on your system.

Update the system package list:

sudo apt-get update

Install the library:

sudo apt-get install ocl-icd-opencl-dev intel-opencl-icd

NOTE: The OpenCL drivers and libraries may vary depending on your system hardware. If you face any errors when installing the OpenCL library on your system, leave us a message below.

Solution 2

If you are still facing the error above after installing the OpenCL library, you can fix it by creating a soft link to the OpenCL library. This will allow the linkers to find the OpenCL library:

sudo ln -s /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 /usr/lib/libOpenCL.so

Solution 3

Instead of creating a soft link to the file, you can tell the linker where to find the library by setting the -L flag during compilation

<compile_command> -L/usr/lib/x86_64-linux-gnu -lOpenCL

Conclusion

This short tutorial provides three main ways of attempting to solve the /usr/bin/ld: cannot find -lOpenCL error when compiling a program in Linux.

Share
Comments
More from Cloudenv

Cloudenv

Developer Tips, Tricks and Tutorials.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Cloudenv.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.