/usr/bin/ld: cannot find -lOpenCL
Solution 1:
You linker can't find the OpenCL
library.
You should help the linker to find the OpenCL
library.
Similar issue was raised here
The solution there was to make a link for the library to a known lib location:
sudo ln -s /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 /usr/lib/libOpenCL.so
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 may need to update the "Dynamic Linker":
sudo ldconfig
Solution 2:
As already stated by Yaron the linker does not know where to find the OpenCL library, i.e. it is in none of the places it looks for it.
Instead of moving it to one of those places (e.g. /usr/lib
) I would suggest to inform the linker where to look for it via the -L
flag.
The command would then read (note the -L/usr/lib/x86_64-linux-gnu
)
g++ DeviceInfo.cpp -I ../../Cpp_common -L/usr/lib/x86_64-linux-gnu -lOpenCL -o DeviceInfo
If you are using a handwritten Makefile
you can simply modify the compiler/linker command like this. Otherwise you will have to touch your build system how to include it.