I’ve just started learning to program in OpenCL, but I’m getting a link error that I’m unable to resolve. I believe I’ve installed everything properly, it’s probably just an error in the way I’ve coded the gcc command. I’m running under Ubuntu 1910 (64-bit), with an Nvidia graphics card. The program just calls clGetPlatformIDs() and prints the results. Here’s the console output:
david$ ls -l /usr/lib/x86_64-linux-gnu/libOpenCL.*
lrwxrwxrwx 1 root root 18 Apr 5 2017 /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 -> libOpenCL.so.1.0.0
-rw-r--r-- 1 root root 43072 Apr 5 2017 /usr/lib/x86_64-linux-gnu/libOpenCL.so.1.0.0
david$ nm -D /usr/lib/x86_64-linux-gnu/libOpenCL.so.1 | grep -i clgetplatform
0000000000005010 T clGetPlatformIDs
00000000000060b0 T clGetPlatformInfo
david$ gcc -DCL_TARGET_OPENCL_VERSION=120 detect.c -L/usr/lib/x86_64-linux-gnu/libOpenCL.so.1
/usr/bin/ld: /tmp/ccCIjSXP.o: in function `main':
detect.c:(.text+0x2d): undefined reference to `clGetPlatformIDs'
collect2: error: ld returned 1 exit status
with the “-L” flag you set the search path for libraries. to use a specific library you have to use the “-l” flag
and usually you dont use the full path with “-l”. try “-lOpenCL”
Yes, I tried that too, but I got a different error (library not found). I tried specifying the file name in full, as well as the abbreviation (“OpenCL”). I also tried both the symbolic link (‘libOpenCL.so.1’ and the actual file (‘libOpenCL.so.1.0.0’). Could it be an issue with dynamic vs. static link libraries?
I found the problem. The symbolic link to the library had a suffix of ‘.1’, which prevented the linker from finding the library. After renaming it from ‘libOpenCL.so.1’ to ‘libOpenCL.so’, I was able to compile and link with the following command (as you suggested):