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. However, I still the get the error above.
How can I solve this error?
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:
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:You may need to update the "Dynamic Linker":
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
)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.