Currently trying to compile a simple program given in OpenCL from this website. It will give me the required DeviceInfo that I need. After simply invoking a make , I get the error below:

sharan@sharan-X550CC:~/opencl-ex/Ex1$ make
g++ DeviceInfo.cpp -I ../../Cpp_common  -lOpenCL -o DeviceInfo
/usr/bin/ld: cannot find -lOpenCL
collect2: error: ld returned 1 exit status
Makefile:23: recipe for target 'DeviceInfo' failed
make: *** [DeviceInfo] Error 1

Now I have installed using the instructions from this website. I still get the error above

What's the fix for this error?

Best Answer

You linker can't find the OpenCL library.

You should help the linker to find the OpenCL library.

Similar issue was raised here

There was a solution to create a link for the library to a known lib location

sudo ln -s /usr/lib/x86_64-linux-gnu/ /usr/lib/

Another option:

Assuming that OpenCL library located in /usr/lib/x86_64-linux-gnu/ you can also add the library folder to the Libraries path.

export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu/"

You might need to update the dynamic linker

sudo ldconfig