Problem building CUDA samples on Ubuntu (GL linking problem)

I’m having trouble building some of the CUDA samples (just the ones that use the GL libs). I’ve got CUDA 10.0 installed on Unbuntu 18.04. I’m using Nvidia driver 418.56. I’m seeing the error below. I’ve added some troubleshooting messages to the Makefile and to findgllib.mk. I don’t understand why ld can’t find the libs - I’ve posted a portion of my lib directory below.

Maybe nvcc isn’t passing the -L argument to ld?

Any ideas?

GLPATH=/usr/lib/x86_64-linux-gnu
GLLINK=-L/usr/lib/x86_64-linux-gnu
DFLT_PATH=/usr/lib
LIBRARIES= -L/usr/lib/x86_64-linux-gnu -lGL -lGLU -lglut
“/usr/local/cuda-10.0”/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_37,code=sm_37 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_52,code=sm_52 -gencode arch=compute_60,code=sm_60 -gencode arch=compute_61,code=sm_61 -gencode arch=compute_70,code=sm_70 -gencode arch=compute_75,code=sm_75 -gencode arch=compute_75,code=compute_75 -o Mandelbrot Mandelbrot.o Mandelbrot_cuda.o Mandelbrot_gold.o -L/usr/lib/x86_64-linux-gnu -lGL -lGLU -lglut
/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status
Makefile:313: recipe for target ‘Mandelbrot’ failed
make: *** [Mandelbrot] Error 1

jayk@jayk-desktop:~/NVIDIA_CUDA-10.0_Samples/2_Graphics/Mandelbrot$ ls -l /usr/lib/x86_64-linux-gnu/libG*
lrwxrwxrwx 1 root root 18 Apr 11 12:58 /usr/lib/x86_64-linux-gnu/libGeoIP.so.1 -> libGeoIP.so.1.6.12
-rw-r–r-- 1 root root 211128 Jan 24 2018 /usr/lib/x86_64-linux-gnu/libGeoIP.so.1.6.12
lrwxrwxrwx 1 root root 22 Aug 14 2018 /usr/lib/x86_64-linux-gnu/libGLdispatch.so -> libGLdispatch.so.0.0.0
-rwxr-xr-x 1 root root 732408 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLdispatch.so.0
lrwxrwxrwx 1 root root 29 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLESv1_CM_nvidia.so.1 -> libGLESv1_CM_nvidia.so.418.56
-rwxr-xr-x 1 root root 60832 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLESv1_CM_nvidia.so.418.56
lrwxrwxrwx 1 root root 21 Aug 14 2018 /usr/lib/x86_64-linux-gnu/libGLESv1_CM.so -> libGLESv1_CM.so.1.0.0
lrwxrwxrwx 1 root root 21 Apr 19 10:37 /usr/lib/x86_64-linux-gnu/libGLESv1_CM.so.1 -> libGLESv1_CM.so.1.2.0
-rw-r–r-- 1 root root 43328 Aug 14 2018 /usr/lib/x86_64-linux-gnu/libGLESv1_CM.so.1.0.0
-rwxr-xr-x 1 root root 43696 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLESv1_CM.so.1.2.0
lrwxrwxrwx 1 root root 26 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLESv2_nvidia.so.2 -> libGLESv2_nvidia.so.418.56
-rwxr-xr-x 1 root root 110784 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLESv2_nvidia.so.418.56
lrwxrwxrwx 1 root root 18 Aug 14 2018 /usr/lib/x86_64-linux-gnu/libGLESv2.so -> libGLESv2.so.2.0.0
lrwxrwxrwx 1 root root 18 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLESv2.so.2 -> libGLESv2.so.2.1.0
-rwxr-xr-x 1 root root 83280 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLESv2.so.2.1.0
-rw-r–r-- 1 root root 671 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGL.la
lrwxrwxrwx 1 root root 14 Aug 14 2018 /usr/lib/x86_64-linux-gnu/libGL.so -> libGL.so.1.0.0
lrwxrwxrwx 1 root root 14 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGL.so.1 -> libGL.so.1.7.0
-rwxr-xr-x 1 root root 685848 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGL.so.1.7.0
-rw-r–r-- 1 root root 926218 May 21 2016 /usr/lib/x86_64-linux-gnu/libGLU.a
lrwxrwxrwx 1 root root 15 May 21 2016 /usr/lib/x86_64-linux-gnu/libGLU.so -> libGLU.so.1.3.1
lrwxrwxrwx 1 root root 15 Apr 11 12:58 /usr/lib/x86_64-linux-gnu/libGLU.so.1 -> libGLU.so.1.3.1
-rw-r–r-- 1 root root 453352 May 21 2016 /usr/lib/x86_64-linux-gnu/libGLU.so.1.3.1
lrwxrwxrwx 1 root root 23 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLX_indirect.so.0 -> libGLX_nvidia.so.418.56
lrwxrwxrwx 1 root root 20 Feb 8 14:02 /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0 -> libGLX_mesa.so.0.0.0
-rw-r–r-- 1 root root 479992 Feb 8 14:02 /usr/lib/x86_64-linux-gnu/libGLX_mesa.so.0.0.0
lrwxrwxrwx 1 root root 23 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLX_nvidia.so.0 -> libGLX_nvidia.so.418.56
-rwxr-xr-x 1 root root 1275632 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLX_nvidia.so.418.56
lrwxrwxrwx 1 root root 15 Aug 14 2018 /usr/lib/x86_64-linux-gnu/libGLX.so -> libGLX.so.0.0.0
-rwxr-xr-x 1 root root 65168 Apr 11 13:21 /usr/lib/x86_64-linux-gnu/libGLX.so.0
jayk@jayk-desktop:~/NVIDIA_CUDA-10.0_Samples/2_Graphics/Mandelbrot$ ls -l /usr/lib/x86_64-linux-gnu/libgl*
lrwxrwxrwx 1 root root 17 Feb 8 14:02 /usr/lib/x86_64-linux-gnu/libglapi.so.0 -> libglapi.so.0.0.0
-rw-r–r-- 1 root root 194808 Feb 8 14:02 /usr/lib/x86_64-linux-gnu/libglapi.so.0.0.0
lrwxrwxrwx 1 root root 23 Apr 11 12:58 /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 -> libglib-2.0.so.0.5600.3
-rw-r–r-- 1 root root 1133872 Sep 26 2018 /usr/lib/x86_64-linux-gnu/libglib-2.0.so.0.5600.3
-rw-r–r-- 1 root root 552990 Aug 23 2016 /usr/lib/x86_64-linux-gnu/libglut.a
lrwxrwxrwx 1 root root 16 Aug 23 2016 /usr/lib/x86_64-linux-gnu/libglut.so -> libglut.so.3.9.0
lrwxrwxrwx 1 root root 16 Aug 23 2016 /usr/lib/x86_64-linux-gnu/libglut.so.3 -> libglut.so.3.9.0
-rw-r–r-- 1 root root 298856 Aug 23 2016 /usr/lib/x86_64-linux-gnu/libglut.so.3.9.0
jayk@jayk-desktop:~/NVIDIA_CUDA-10.0_Samples/2_Graphics/Mandelbrot$

Just figured it out… the symbolic link for libGL was pointing a file that doesn’t exist. Fixed that and everything is good now.

In my case libGL.so was pointing to a non existing libGL.so.1.7.0

this fixed it for me:

sudo ln -sf /usr/lib/x86_64-linux-gnu/libGL.so.1 /usr/lib/x86_64-linux-gnu/libGL.so