Linker "cannot find -lGL"

Hi all,

Im currently having troubles setting up OpenGL with my system. Im using codeblocks and have added SDL2, GLEW, and GL to the linker libraries. I installed these three using apt-get with no problems. When I try to build I get the output:

ld||cannot find -lGL|

I don’t really know much except that i think it is looking through /usr/lib/ld. Here is some graphics info, just in case it is relevent to the problem somehow:

$ glxinfo | grep OpenGL
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 660/PCIe/SSE2/3DNOW!
OpenGL core profile version string: 4.3.0 NVIDIA 346.35
OpenGL core profile shading language version string: 4.30 NVIDIA via Cg compiler
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 4.5.0 NVIDIA 346.35
OpenGL shading language version string: 4.50 NVIDIA
OpenGL context flags: (none)
OpenGL profile mask: (none)
OpenGL extensions:

To really get what I am doing, I pretty much followed this video step by step : #1.5 Intro to Modern OpenGL Tutorial: Linux Setup - YouTube

I’m hoping that this is a really common problem with a simple solution and that the search engine gods just haven’t been nice to me. If this isn’t the case and you need more info, I’ll be happy to give it.


ldd `which glxinfo`

That’ll tell you where your GL library lives. Most likely /usr/lib64 (64-bit) or /usr/lib (32-bit).

Then point your linker to that library, either explicitly with a full path to the library, or by adding a library search path with -L.

However, typically you don’t need to do that because 1) the GL library is in a system library directory, and 2) that directory is searched by ld by default (unless somebody’s overriden that behavior with -nostdlib.

Do you need to install the “-devel” package?

Typically, shared libraries have 3 filenames: the actual file has a name which includes the complete version number (e.g., then there’s a symlink which only includes the major version number (e.g. and another which doesn’t contain any part of the version number (e.g.

The library name stored in the executable uses the name with the major version number, so that you can upgrade to a newer minor version without needing to re-link the executable. A different major version number normally indicates some form of incompatibility, so executables compiled for one major version shouldn’t attempt to use a different major version.

The (compile-time) linker uses the name without any version number. E.g. -lGL will cause the linker to look for or (if that isn’t found) libGL.a.

Because the symlink without the version number is only needed for compiling, and not for running programs which use the library, it’s often part of a separate “-devel” package (e.g. “opengl-devel” or similar) which must be installed separately from the package containing the library.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.