-2

eI'm trying to compile a c++ openGL program using libGL and freeglut3. Im trying:

g++ main.cpp -w -lglut -lGl -o bin/app

or

g++ main.cpp -w -lglut -lGL -o bin/app

Which results in:

/usr/bin/ld: cannot find -lGl
collect2: error: ld returned 1 exit status
Makefile:16: recipe for target 'all' failed
make: *** [all] Error 1

I'm on:

Ubuntu 16.04 LTS

GCC:

gcc version 5.3.1 20160413 (Ubuntu 5.3.1-14ubuntu2)

libGL.so

/usr/lib/x86_64-linux-gnu$ find libGL.so
libGL.so

I installed:

freeglut3 freeglut3-dev libglew1.5 libglew1.5-dev libglu1-mesa libglu1-mesa-dev libgl1-mesa-glx libgl1-mesa-dev

Am I missing anything? Last time I successfully compiled I was on ubuntu 14.04.

I read somewhere that I should install fglrx-glx but the package is not available.

Update:

glxinfo
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 5500 (Broadwell GT2) 
OpenGL core profile version string: 3.3 (Core Profile) Mesa 11.2.0
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 11.2.0
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.1 Mesa 11.2.0
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.10
OpenGL ES profile extensions:

My ldconfig.real appears to be empty

Nick
  • 461
  • 2
  • 6
  • 16

2 Answers2

5

g++ main.cpp -w -lglut -lGl -o bin/app

This command is incorrect: you want to link against libGL, not libGl, so the command should be: g++ main.cpp -w -lglut -lGL -o bin/app

UNIX file names are case-sensitive.

I know its Gl for sure, but I tried -lGL and it gave the same error

You know wrong. It should be -lGL, and with libGL.so present in /usr/lib/x86_64-linux-gnu there is no way you are getting the same error (possibly you get a different error from ld (which matters) but the same error from make (which doesn't matter)).

Update:

/usr/bin/ld: cannot find -lGL

Ok. It must be that /usr/lib/x86_64-linux-gnu/libGL.so is either a dangling symlink, or points to a 32-bit library, or is corrupt in some other way.

Update 2:

 /usr/lib/x86_64-linux-gnu/libGL.so: broken symbolic link to /usr/lib/libGL.so.1.2 2

Indeed it's a broken symlink. To fix this, reinstall the package which provides it:

sudo apt-get install --reinstall libgl1-mesa-dev
Employed Russian
  • 199,314
  • 34
  • 295
  • 362
  • /usr/bin/ld: cannot find -lGL collect2: error: ld returned 1 exit status Makefile:16: recipe for target 'all' failed make: *** [all] Error 1 – Nick May 07 '16 at 19:00
  • 1
    @Nick What is the output from `file /usr/lib/x86_64-linux-gnu/libGL.so` and `file -L /usr/lib/x86_64-linux-gnu/libGL.so` ? – Employed Russian May 07 '16 at 20:34
  • hmmm... 1st: /usr/lib/x86_64-linux-gnu/libGL.so: broken symbolic link to /usr/lib/libGL.so.1.2 2nd: /usr/lib/x86_64-linux-gnu/libGL.so: cannot open `/usr/lib/x86_64-linux-gnu/libGL.so' (No such file or directory) I think you might have found my problem – Nick May 08 '16 at 14:16
  • @Nick "I think you might have found my problem" -- do you have *doubts* that I have? Answer updated. – Employed Russian May 08 '16 at 16:25
  • No doubts... :P just looking for a way to fix it – Nick May 08 '16 at 16:36
  • Thanks anway :) With those 2 commands I was able to view what is wrong and fix the symlinks! – Nick May 09 '16 at 06:13
2

I had the same problem and I managed to fix it, I don't know if it can be a problem later on, but for now it's going well.

Inside the /usr/lib/x86_64-linux-gnu directory I checked which files the symbolic links made, and I saw that in my case there was no libGL.so.In your case it even exists, you can try to delete it and create the symbolic link again.

What I did was create the symbolic link with libGL.so.1.7.0 (1.7.0 can be changed by the version on your machine).

sudo ln -s libGL.so.1.7.0 libGL.so

I hope this solution works for someone, sorry for the strange English.