Symptoms

Command make failed with error like “ld cannot find l" .

Detail messages are like below

/usr/bin/ld: cannot find -lOpenCL
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:20: DeviceInfo] Error 1

Cause

gcc or g++ cannot find -l<nameOfTheLibrary>, it means that the compiler looked for the file lib{nameOfTheLibrary}.so, but it couldn’t find it in the shared library search path, which by default points to /lib and /usr/lib and the path included by /etc/ld.so.conf . Or if you have environment variable LD_LIBRARY_PATH set , the directories listed will be the search path.

Solution

The solution is to make a symbolic link for the library to a known library location ,for example:

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

Alternatively , you can also use env variable LD_LIBRARY_PATH to archive this , or edit /etc/ld.so.conf.d/myapp.conf then run command ldconfig to update your library path.

wait , but how do I know where is the library file

You can use command locate or find to get the location of the so file ,eg:

root@ubuntu:/home/j/Desktop# locate libOpenCL.so
/usr/lib/x86_64-linux-gnu/libOpenCL.so.1
/usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
/usr/share/man/man7/libOpenCL.so.7.gz
root@ubuntu:/home/j/Desktop# find / -name 'libOpenCL.so*'
/usr/lib/x86_64-linux-gnu/libOpenCL.so.1
/usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
/usr/lib/x86_64-linux-gnu/libOpenCL.so
/usr/share/man/man7/libOpenCL.so.7.gz
find: ‘/run/user/1000/doc’: Permission denied
find: ‘/run/user/1000/gvfs’: Permission denied
root@ubuntu:/home/j/Desktop#

In case you can find it ,then you need to install it .