21

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?

Yaron
  • 13,453
SDG
  • 447

2 Answers2

26

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
Yaron
  • 13,453
3

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.

mbeyss
  • 1,038