Question

I'm failing to link against OpenGL in my C++/Qt5 projects. I link using the following command:

g++ -m64 -Wl,[...] -o [...] [...].o                               \
    -L/usr/X11R6/lib64 -L[...]/qt-5.0.0/5.0.0/gcc_64/lib          \
    -lQt5Widgets -lQt5Network -lQt5Gui -lQt5Core -lGL -lpthread 

I hope the [...] aren't hiding something important. If you think they are, please let me know.

I get the following error:

/usr/bin/ld: cannot find -lGL

I'm on an Lubuntu 12.10 system and using Qt5 from http://qt-project.org/downloads. Since the system is newly installed, the first thing I did was installing Ubuntu's nvidia-current package and I rebooted. Among others, the following libraries have been installed on my system:

$ ll /usr/lib/nvidia-current/
[...]
lrwxrwxrwx   1 root root       10 Oct  6 04:58 libGL.so -> libGL.so.1
lrwxrwxrwx   1 root root       15 Oct  6 04:58 libGL.so.1 -> libGL.so.304.43
-rw-r--r--   1 root root  1076560 Oct  6 04:58 libGL.so.304.43
[...]

I googled on how to add this path to the default library search path, as I guessed that g++ doesn't look in the subfolder nvidia-current but only in /usr/lib. So I added the path to ld.conf.d in Ubuntu. I updated ldconfig and checked with the following command:

$ ldconfig -p | grep libGL.so
        libGL.so.1 (libc6,x86-64) => /usr/lib/nvidia-current/libGL.so.1
        libGL.so.1 (libc6) => /usr/lib32/nvidia-current/libGL.so.1
        libGL.so (libc6,x86-64) => /usr/lib/nvidia-current/libGL.so
        libGL.so (libc6) => /usr/lib32/nvidia-current/libGL.so

So everything looks just fine! Still (even after rebooting), the error from above appears. Am I missing something?

Edit:

After adding -L/usr/lib/nvidia-current/, everything works fine. But it seems that this is not the correct way to link against a library in a default path.

Was it helpful?

Solution

It's common for distributions to install graphics drivers' libGL not into the system library path, but some additional directory in /usr/lib to allow for installing different variants of libGL.so on the same system. Then symlinks to the active libGL.so are created by some centralized configuration system, for example alternatives as used by Ubuntu and Debian. It may very well be, that this configuration step failed.

/usr/lib/nvidia-current is not a standard library path and hence the library is not found; this also should mean, that OpenGL programs should not work. Maybe the Ubuntu folks do something with the LD_LIBRARY_PATH environment variable to circumvent this.

Personally I suggest that you add symlinks, as you should always have libGL.so in the defaul library path, preferrably /usr/lib or on 32/64 bit multilib systems in /usr/lib64 and /usr/lib32

/usr/lib/libGL.so.1 => /usr/lib/nvidia-current/libGL.so.1
/usr/lib32/libGL.so.1 => /usr/lib32/nvidia-current/libGL.so.1
/usr/lib/libGL.so => /usr/lib/nvidia-current/libGL.so
/usr/lib32/libGL.so => /usr/lib32/nvidia-current/libGL.so

You can also do this using the alternatives system, adding a new alternative.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top