Linking error for old Nvidia Card on Opensuse Tumbleweed

Hallo Everybody,
on my Laptop there is a Nvidia Card, GeForce GT 730M. I installed the drivers from the Nvidia Repository for Opensuse Tumbleweed. Its a 64bit machine. The compute rpm of Nvidia provides the following files:

/usr/bin/nvidia-cuda-mps-control
/usr/bin/nvidia-cuda-mps-server
/usr/bin/nvidia-modprobe
/usr/bin/nvidia-smi
/usr/lib64/libOpenCL.so.1
/usr/lib64/libcuda.so
/usr/lib64/libcuda.so.1
/usr/lib64/libcuda.so.470.129.06
/usr/lib64/libnvidia-ml.so
/usr/lib64/libnvidia-ml.so.1
/usr/lib64/libnvidia-ml.so.470.129.06
/usr/lib64/libnvidia-opencl.so.1
/usr/lib64/libnvidia-opencl.so.470.129.06
/usr/lib64/libnvidia-ptxjitcompiler.so.1
/usr/lib64/libnvidia-ptxjitcompiler.so.470.129.06
/usr/lib64/nvidia
/usr/lib64/nvidia/libOpenCL.so.1
/usr/lib64/nvidia/libOpenCL.so.1.0.0

But when I want to compile my little test programm with g++ main.cpp -lOpenCL the compiler can’t link to OpenCL:

/usr/lib64/gcc/x86_64-suse-linux/12/../../../../x86_64-suse-linux/bin/ld: cannot find -lOpenCL: Datei oder Verzeichnis nicht gefunden
collect2: error: ld returned 1 exit status

How can I make the linker to find OpenCL? This error persisted over many Updates of Nvidia’s kernel modules.

Kind regardes,
Tobias

Hi. Fellow NVIDIA and OpenSUSE user here. Though what you’re hitting here applies not only to OpenSUSE but other Linux distros as well.

The key item you’re missing is a symlink from /usr/lib64/libOpenCL.so.1 to /usr/lib64/libOpenCL.so. For testing, you can create this by running the following command as root:

ln -s /usr/lib64/libOpenCL.so.1 /usr/lib64/libOpenCL.so

Then retry your link. It should work.

However, you’re probably wondering why this symlink isn’t already here. Well, oftentimes packages providing library dependencies are split into a base package RPM (needed for running apps linked against the package) and a “devel” package RPM. The base package contains the actual versioned library files (e.g. libOpenCL.so.1.0.0) as those are needed for runtime linking. And the devel package contains the files needed only for building (compiling and compile-time linking) with the application. The latter includes header (.h) files and symlinks to the versioned libraries from unversioned filenames (e.g. libOpenCL.so).

So I would look for a package with the same name as the one that provided the NVIDIA compute libraries, but which also has a “-devel-” in the package name. That’ll be the one to provide headers and shared library symlinks needed for building with that package’s libraries.

FWIW, here back on OpenSuSE 15.0, they hadn’t done that split, and both the versioned library files and library symlinks were all provided by the same package:

> rpm -qf /usr/lib64/libOpenCL.so /usr/lib64/libOpenCL.so.1 /usr/lib64/libOpenCL.so.1.0.0
nvidia-computeG05-460.84-lp150.40.1.x86_64                                      
nvidia-computeG05-460.84-lp150.40.1.x86_64                                      
nvidia-computeG05-460.84-lp150.40.1.x86_64                                      

> ls -l /usr/lib64/libOpenCL.so /usr/lib64/libOpenCL.so.1 /usr/lib64/libOpenCL.so.1.0.0
lrwxrwxrwx 1 root root    14 Jun 17  2021 /usr/lib64/libOpenCL.so -> libOpenCL.so.1
lrwxrwxrwx 1 root root    18 Jun 17  2021 /usr/lib64/libOpenCL.so.1 -> libOpenCL.so.1.0.0
-rwxr-xr-x 1 root root 30856 Jun 17  2021 /usr/lib64/libOpenCL.so.1.0.0

Dear Dark_Photon,

Thank you for your amazingly fast answer. Making the sysmlink solved the problem
instantaneously:

ln -s /usr/lib64/libOpenCL.so.1 /usr/lib64/libOpenCL.so

Kind regards,
Tobias