"/usr/bin/ld: cannot find -lGL" impossible to compile a project with the graphical library

Since I bought a new computer (I installed Debian stretch with Qt 5.10.1, and use NVIDIA-Linux-x86_64-390.42.run to install the driver), I can’t anymore compile a Qt project. I always end on the following message : “/usr/bin/ld: cannot find -lGL”
After going through many forum, I can already tell you that I already install libglapi-mesa, libgl1-mesa-dev, libgles1-mesa-dev, libgles2-mesa-dev and xorg-dev, but I still end in the same compile error.

Of course, if I delete -lGL from the Makefile I can compile but I would like to be able to include this library.

As anyone an idea about what I am missing ?

When using the .run installer, you have to use the --opengl-headers option to install the headers.

Though you should rather install mesa-common-dev which also includes those headers.

Post the contents of /usr/lib/pkgconfig/gl.pc
(The location may be different on your Linux installation)

Hello generix,
mesa-common-dev is already installed on my computer.
I tried the command :

sh NVIDIA-Linux-x86_64-390.42.run --opengl-headers

But as I have already installed the driver, I end in an error. Here is my nvidia-installer.log:

nvidia-installer log file '/var/log/nvidia-installer.log'
creation time: Fri Jun 15 18:00:18 2018
installer version: 390.42

PATH: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

nvidia-installer command line:
    ./nvidia-installer
    --opengl-headers

Unable to load: nvidia-installer ncurses v6 user interface

Using: nvidia-installer ncurses user interface
-> Detected 8 CPUs online; setting concurrency level to 8.
ERROR: An NVIDIA kernel module 'nvidia-drm' appears to already be loaded in your kernel.  This may be because it is in use (for example, by an X server, a CUDA program, or the NVIDIA Persistence Daemon), but this may also happen if your kernel was configured without support for module unloading.  Please be sure to exit any programs that may be using the GPU(s) before attempting to upgrade your driver.  If no GPU-based programs are running, you know that your kernel supports module unloading, and you still receive this message, then an error may have occured that has corrupted an NVIDIA kernel module's usage count, for which the simplest remedy is to reboot your computer.
ERROR: Installation has failed.  Please see the file '/var/log/nvidia-installer.log' for details.  You may find suggestions on fixing installation problems in the README available on the Linux driver download page at www.nvidia.com.

Is there a way to make it install the headers without installing the driver ?

Hello HussamT,
I have found the file at this address :

/usr/lib/x86_64-linux-gnu/pkgconfig/

Here is the content :

prefix=/usr
exec_prefix=${prefix}
libdir=${prefix}/lib/x86_64-linux-gnu
includedir=${prefix}/include

Name: gl
Description: Mesa OpenGL library
Requires.private:  libdrm >= 2.4.66 x11 xext xdamage xfixes x11-xcb xcb xcb-glx >= 1.8.1 xcb-dri2 >= 1.8 xxf86vm
Version: 13.0.6
Libs: -L${libdir} -lGL
Libs.private: -lm -lpthread -ldl
Cflags: -I${includedir} 
glx_tls: yes

Does it help ?

The file looks ok.
Check for /usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGL.so.1 /usr/lib/x86_64-linux-gnu/libGL.so.1.0.0
The first two should point to the third.
If they exist, run ‘ldconfig’ as root.

I’m not really sure how using the binary installer would interact with glvnd. Would also depend on the initial options you chose. Please run nvidia-bug-report.sh as root and attach the resulting .gz file to your post. Hovering the mouse over an existing post will reveal a paperclip icon.

Hello HussamT,
First I didn’t found the file “libGL.so.1.0.0”
The first link point to libGL.so.1.2.0 which is a file I didn’t found.
The second link point to libGL.so.1.7.0 which is a file that exist.

lrwxrwxrwx 1 root root   14 avril 25  2017 /usr/lib/x86_64-linux-gnu/libGL.so -> libGL.so.1.2.0
lrwxrwxrwx 1 root root   14 avril  1 00:48 /usr/lib/x86_64-linux-gnu/libGL.so.1 -> libGL.so.1.7.0
-rwxr-xr-x 1 root root 651K avril  1 00:48 /usr/lib/x86_64-linux-gnu/libGL.so.1.7.0

I called for ldconfig as root but nothing happend.

generix, you will find the file in attachement.

nvidia-bug-report.log.gz (99.1 KB)

Anything after the .so.1 doesn’t matter (as long as it exists) however there shouldn’t be both libGL.so.1.2.x and libGL.so.1.7.x as far as I can tell. I don’t know for sure though.
But I believe libGL.so.1 and libGL.so should point to the same file which is not the case on your installation.
In other words, it should be:

/usr/lib/x86_64-linux-gnu/libGL.so -> libGL.so.1.2.0
/usr/lib/x86_64-linux-gnu/libGL.so.1 -> libGL.so.1.2.0

or

/usr/lib/x86_64-linux-gnu/libGL.so -> libGL.so.1.7.0
/usr/lib/x86_64-linux-gnu/libGL.so.1 -> libGL.so.1.7.0

as long as it’s NOT the mesa libGL.so.1.x.x because it should be either the NVIDIA one or the libglvnd one.

It’s like HussamT said, replace the link for libGL.so so it points to
/usr/lib/x86_64-linux-gnu/libGL.so → libGL.so.1.7.0
libGL.so.1.7.0 should be the glvnd stub library installed by the nvidia installer. 1.2.0 was installed by mesa and removed by the .run installer.

It worked now I can compile, thank you very much to you all !
I would never have found this by myself.