/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.
Related videos on Youtube
SDG
Updated on September 18, 2022Comments
-
SDG over 1 year
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 amake
, 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?
-
steeldriver about 6 yearsor try
LDFLAGS
e.g.make 'LDFLAGS=-L/usr/lib/x86_64-linux-gnu'
-
mbeyss about 6 yearsIf your looking for a purely temporary solution this will also do the trick. However I advise to make it
LDFLAGS=$LDFLAGS:/usr/lib/x86_64-linux-gnu/
to preserve any previous settings -
SDG about 6 yearsThis worked for me! The very first answer. Thank you!