GCC /usr/bin/ld: cannot find -lGl

风格不统一 提交于 2021-02-08 12:13:47

问题


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


回答1:


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



回答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. 👍

🧙



来源:https://stackoverflow.com/questions/37081298/gcc-usr-bin-ld-cannot-find-lgl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!