124

I just reinstalled QtCreator, created new project (Qt Application) an got this after compilation:

/usr/bin/ld: **cannot find -lGL**
collect2: error: ld returned 1 exit status
make: *** [untitled1] Error 1
18:07:41: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project untitled1 (kit: Desktop Qt 5.1.0 GCC 32bit)
When executing step 'Make'

(Project is empty, I did'n commit any changes)

Qt Creator 2.7.2
Based on Qt 5.1.0 (32 bit)
Ubuntu 13.04

How do I solve this problem?

László Papp
  • 51,870
  • 39
  • 111
  • 135
Hofmn
  • 1,343
  • 2
  • 9
  • 4
  • do you have opengl installed? – László Papp Aug 23 '13 at 19:29
  • possible duplicate of [Android : error libGL.so: cannot open shared object file: No such file or directory](http://stackoverflow.com/questions/17417211/android-error-libgl-so-cannot-open-shared-object-file-no-such-file-or-direct) – László Papp Apr 12 '14 at 06:20
  • 1
    Possible duplicate of [Qt Creator compiler issue on Debian](http://stackoverflow.com/questions/33254272/qt-creator-compiler-issue-on-debian) –  Oct 22 '15 at 07:39

8 Answers8

184

You should install package "libgl1-mesa-dev":

sudo apt install libgl1-mesa-dev
Rando Hinn
  • 1,255
  • 19
  • 41
Sayyed Hassan Amiri
  • 2,042
  • 1
  • 13
  • 7
  • 6
    How is this the correct answer? Why should you link against a library not being used? Shouldn't the linker flags simply not include `-lGL`? – Cuadue Oct 07 '14 at 16:28
  • 7
    @Cuadue: The GL in the error and in libgl1-... is for OpenGL, a fundamental dependency of Qt 5.x. This is a common error for devs when setting up for Qt development -- but once they install the OpenGL development lib they never see it again. – pixelgrease Jun 04 '15 at 23:04
  • Ubuntu 20.04 ships with the required OpenGL libraries, it's not necessary to install any packages, you just need to use `ln` to create a link in /usr/lib, see [destan's answer](https://stackoverflow.com/a/32184137/4975230), the [20.04 package](https://packages.ubuntu.com/focal/amd64/libgl1-mesa-dev/filelist) doesn't seem to have anything useful in it. – jrh May 04 '20 at 13:53
81

you don't need to install anything. libGL is already installed with Ubuntu, you just need to soft link it. (tested for ubuntu 14.x and 15.x, might work for later versions)

  1. First locate the GL library
  2. Then link it under /usr/lib
  3. If the library is missing, it can be installed via libgl1-mesa-dev package

Here is how you could do this:

$ locate libGL
/usr/lib/i386-linux-gnu/mesa/libGL.so.1
/usr/lib/i386-linux-gnu/mesa/libGL.so.1.2.0
/usr/lib/x86_64-linux-gnu/libGLEW.so.1.10
/usr/lib/x86_64-linux-gnu/libGLEW.so.1.10.0
/usr/lib/x86_64-linux-gnu/libGLEWmx.so.1.10
/usr/lib/x86_64-linux-gnu/libGLEWmx.so.1.10.0
/usr/lib/x86_64-linux-gnu/libGLU.so.1
/usr/lib/x86_64-linux-gnu/libGLU.so.1.3.1
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1
/usr/lib/x86_64-linux-gnu/mesa/libGL.so.1.2.0
/usr/lib/x86_64-linux-gnu/mesa-egl/libGLESv2.so.2
/usr/lib/x86_64-linux-gnu/mesa-egl/libGLESv2.so.2.0.0
$ sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so
destan
  • 4,301
  • 3
  • 35
  • 62
  • 1
    Yep, this works. It's usually a good idea to run `ldconfig` after dealing with shared libraries like in this case. – José Tomás Tocino May 11 '16 at 19:42
  • Thanks for the answer! On my system I had multiple libGL because of Android sdk, steam and other applications. The original mesa folder was also present in `i386-linux-gnu` folder. For anyone reading this answer, you can easily locate the default installed library in Ubuntu by running `locate libGL | grep mesa` and then alter the last `sudo ln` command mentioned in this answer with the right location. – Akash Agarwal May 28 '16 at 11:28
  • 1
    This worked for me on Ubuntu 16.10, but I'm confused if it is now using the NVidia GPU for OpenGL rendering, or a s/w renderer? – DavidJ Jan 12 '17 at 16:44
  • This answer doesn't seem to solve the pkg-config question, does it? IE: if you have qt build lines set up to use pkg-config --libs, this solution still won't return anything for GL? To be on the safe side, I simply installed the mesa-dev. – Alex Summers Jun 15 '17 at 14:01
  • 3
    You Sir, deserve the cookie not the con-man who was the big tick – codingbruh Jun 06 '18 at 16:37
  • For me on Ubuntu 18.04 I link it on the same location using following command. sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so.1.0.0 /usr/lib/x86_64-linux-gnu/libGL.so – PoundXI May 28 '19 at 16:14
  • linking the file did not solve the problem in my case, the compiler complained: `/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: skipping incompatible /usr/lib/libGL.so when searching for -lGL /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: cannot find -lGL` – mx1up Jul 11 '19 at 20:02
  • 3
    That worked for my on Ubuntu 18.04 and Qt 5.12.6. `sudo ln -s /usr/lib/x86_64-linux-gnu/libGL.so.1 /usr/lib/libGL.so` – RichArt Dec 30 '19 at 04:01
  • 1
    I'd like to recommend this solution. It worked with my Ubuntu 16.04 LTS and Qt 5.0.2 (5.15.2 based) `sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so ` – iroiroys Jan 03 '22 at 01:40
4

The gui Qt module is included by default. If you don't want to use it in a project (e.g., it is a library or only uses stdio), you need to specify that in the .pro file.

QT -= gui

And the linker won't attempt to find lGL regardless of whether it is installed.

My case is admittedly a bit odd, since the main reason to use Qt is to create gui's. Installing the GL library is certainly not difficult, I just wanted to know why my quick and dirty Hello World wanted it.

squeevee
  • 141
  • 9
2

write:

yum provides */libGL.so 

after providing:

yum install mesa-libGL-devel mesa-libGLU-devel
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1

This worked for me:

sudo ln -s /usr/lib/libEGL1.so /usr/lib/libGL.so
Sebastian Karlsson
  • 715
  • 1
  • 8
  • 19
1

My system is Ubuntu 16.04 on x86 computer(with NVIDIA GeForce GPU).

Check the library files located in /usr/lib/x86_64-linux-gnu

ls -al /usr/lib/x86_64-linux-gnu/libG*

If you see the broken link, reinstall libgl1-mesa-glx

sudo apt install --reinstall libgl1-mesa-glx

And, recheck library.

truf
  • 2,843
  • 26
  • 39
Lastea
  • 11
  • 2
0

In my case: I have installed QT 32 bit lib in Win10 64 bit and it ran into error, I change to all 64 bit and QT creator run smoothly.

nobjta_9x_tq
  • 1,205
  • 14
  • 16
-1

Solved this problem just a minute ago in suse. Just do the following step below and QTCreator should works just fine.

sudo zypper install --type pattern devel_basis