29

I'm having a hard time trying to install Qt on linux. I downloaded the .run file on the website and installed Qt. However, when I try to compile the default Hello World project using Qtcreator, I get the following :

error cannot find -lGL

I was able to solve the problem by issuing the command :

sudo apt-get install libqt4-dev

But, I'm not satisfied with the solution as I want to use Qt5 and the name of the lib I downloaded implies version 4. Can someone explain what is going on and tell me if my solution is correct? If not, what should I do to get a working Qt on Linux.

Additional question

The correct answer, as provided by LtWorf, was to install libgl-dev. For future problems of this sort, can someone tell me how I should have guessed that I had to download this particular library? And why are there some libs with -dev at the end? What do they provide?

Gradient
  • 2,253
  • 6
  • 25
  • 36
  • 8
    hey googlers, don't install libraries to solve this problem, see http://stackoverflow.com/a/32184137/878361 – destan Aug 24 '15 at 13:58
  • Just removing -lGL from LIBS in Makefile also works for me. My projects build without any libgl, apparently. – MKaama May 30 '17 at 14:37

5 Answers5

43

Well it is trying to link with libgl and doesn't find it. You should install libgl-dev.

-l is a linker option, it tells the linker to use a certain library. For example you can have -lmagic meaning that you want to use libmagic.

Normally all libraries are called libsomething, and on debian you will find 3 packages called: libsomething libsomething-dbg libsomething-dev

The 1st one is the library, the second one is the library compiled with the debug symbols, so you can make sense of stacktraces more easily, and the final one is the development package, it contains the .h files so you can link to the library.

LtWorf
  • 7,286
  • 6
  • 31
  • 45
  • Thank you. I will mark your answer as the answer soon. I added another question to my original question, which you might know the answer. – Gradient Mar 12 '13 at 23:55
  • Done. It would have been enough from you to type apt-cache show libgl-dev, to see the description of the package. – LtWorf Mar 13 '13 at 07:20
  • Thank you. I didn't know about this command. Anyway, I tried it and it says it is purely virtual. – Gradient Mar 13 '13 at 22:19
  • Yes but it will pull in the necessary real packages. – LtWorf Mar 14 '13 at 06:40
  • while this answer is working it's not recommanded at all. Moreover, the correct lib is already installed juste follow destan recommandations – dlewin Feb 19 '20 at 14:49
  • @dlewin why is it not recommended at all? And if the correct library was installed it would be found. Also package manager is how things are installed. – LtWorf Feb 19 '20 at 23:00
  • @LtWorf The package manager is not the point here. It's not because the lib were not found during linking step that it doesn't exist on your system. A simple "locate libGL + ln ...." is better than installing unecessary library. Before posting my comment I've been tested it from my PC – dlewin Feb 20 '20 at 15:32
  • @dlewin If you read the edit, he was missing the headers to the library, so locate wouldn't locate anything… – LtWorf Feb 21 '20 at 08:01
  • @LtWorf 1/ his edit is about libqt4-dev which is different than libgl-dev compare the both : * https://packages.debian.org/sid/libqt4-dev * https://packages.debian.org/sid/libgl-dev (as he didn't give detail on OS Debian sid is an example here) 2/ I've seen this question because I had the same problem and once again your solution *could* resolve this but this is not the best way when you already have the lib installed – dlewin Feb 21 '20 at 10:29
  • @dlewin I repeat, he did not have the lib installed. Probably that library depended on the one he needed so as a result of him installing the wrong one, it got installed as well. Anyway, you are free to believe what you like, I'll reply no more. – LtWorf Feb 21 '20 at 23:57
7

sudo apt-get install libgl-dev

Triangle
  • 1,477
  • 3
  • 22
  • 36
5

On Fedora 17, I did:

sudo yum install mesa-libGL-devel
joaolsouzajr
  • 326
  • 3
  • 4
1

Do you have libgl-dev installed? If not install it and it should work.

Zlatomir
  • 6,964
  • 3
  • 26
  • 32
0

Those other posters are correct, but on some systems, the lib to install is named differently. I just dealt with a 32bit Ubuntu 14.04.5 LTS system, and libgl-dev was not available.

Instead, I needed to install the libgl1-mesa-dev package via:

sudo apt-get install libgl1-mesa-dev