Linker cannot find opengl libraries :(

Hey guys, I’ve been trying to setup opengl on my computer for the last few days. I’ve been searching these forums like crazy and it has been incredibly helpful, so thanks to everyone for their good responses in the past.

Currently, i’m trying to run a simple file to draw some shapes that the graphics teacher at my school gave me. The includes look like this:

#include <stdio.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

The project uses a main, so it IS a win32 console application. When running the project it gives the error:

Linking…
LINK : fatal error LNK1104: cannot open file “opengl32.lib”
Error executing link.exe.

The files are correctly linked into the project through the settings, and C:\Program Files\Microsoft Visual Studio\VC98\Lib\gl directory contains opengl32.lib glut32.lib and glu32.lib. I tried moving the opengl32.lib file out of the gl directory (heh couldn’t think of anything else to tinker with) and I got the same error except for the glut32.lib file rather than the opengl32.lib file.

I haven’t found a good solution in the forums. Any similar problems were solved by linking the files correctly in VC or by putting the .lib files in the correct directory.

I suppose I could just have bad .lib files, but I’m not particularly sure where to get better ones. Any help is greatly appreciated. Thanks guys!

hi, my glu32.lib glaux.lib and opengl32.lib are on C:\Program Files\Microsoft Visual Studio\VC98\Lib. you say yours are on a gl folder i never seen a folder inside the lib folder

HEllo there,
For the linker errors make sure that the paths to folder to the opengl headers and lib are set in your compiler have a look t compiler docs for help on this. As for opengl32.lib it comes with the opengl sdk for the platform so if you have installed the sdk correctly opengl32.lib would be present in your system.

Heh, yea… The gl directory is for the headers, not libraries. I got a bit confused there. I’m back to getting a bunch of link errors:

Linking…
i.obj : error LNK2001: unresolved external symbol _glFlush
i.obj : error LNK2001: unresolved external symbol _glEnd
i.obj : error LNK2001: unresolved external symbol _glVertex2d
i.obj : error LNK2001: unresolved external symbol _glBegin
i.obj : error LNK2001: unresolved external symbol _glColor3d
i.obj : error LNK2001: unresolved external symbol _glClear
i.obj : error LNK2001: unresolved external symbol _gluErrorString
i.obj : error LNK2001: unresolved external symbol _glGetError
i.obj : error LNK2001: unresolved external symbol _gluOrtho2D
i.obj : error LNK2001: unresolved external symbol _glLoadIdentity
i.obj : error LNK2001: unresolved external symbol _glMatrixMode
i.obj : error LNK2001: unresolved external symbol _glLineWidth
i.obj : error LNK2001: unresolved external symbol _glClearColor
Debug/TestProject.exe : fatal error LNK1120: 13 unresolved externals
Error executing link.exe.

I checked yet again just to make SURE i had added the opengl32.lib, glut32.lib and glu32.lib to the link settings of the project. All the files that I need are now in their appropriate places. Any ideas what could be causeing those linking errors?

Oh and I did set the paths to the lib files and headers in the compiler but it still is throwing the link errors now :frowning: .

Thanks again guys!

  1. Click on Project and then Settings
  2. Select the “Link” tag
  3. Include the following libraries before Kernel32.lib
    OpenGL32.lib GLu32.lib GLaux.lib
  4. Click Ok

That will include libraries into your project

try linking them at compile time using:

 
#pragma commment(lib,"opengl32.lib") 

The libraries are all linked in the settings. I tried loading all 3 at compile time as per the pragma command shown, however it still gives the link errors along with warnings:

c:\program files\microsoft visual studio\myprojects estproject\source files\i.cpp(13) : warning C4068: unknown pragma
c:\program files\microsoft visual studio\myprojects estproject\source files\i.cpp(14) : warning C4068: unknown pragma
c:\program files\microsoft visual studio\myprojects estproject\source files\i.cpp(15) : warning C4068: unknown pragma

Those warnings may be becase I also left the lib files as linked in the settings. When running without the links set in VC++ settings and the pragma comments inserted, I continue to get the same linking errors as before :frowning: .

can you send me your code, so i can check it?

My thanks to Zukko for looking over the code to make sure everything looked good. We found a few things to fix, however the linking errors are still showing up.

I tried something new today also. I figured maybe the lib files I got from microsoft were bad. Everywhere I read said that winXP should already have the opengl32.dll and the glu32.dll files, but my system directory didn’t have them. I downloaded the ones for windows 95 from microsoft. Today I noticed I did have those DLL’s in the system32 folder, so I copied them over to the system folder, but I still get those same link errors. Then off the small chance that the stuff I had been reading was wrong, I copied glut32.dll to the system32 folder, just in case that was where my project was trying to grab its .dll files. That didn’t work either :frowning: .

Any other thoughts? Any recommended windows compilers I should try using instead of VC 6.0? Maybe I can get a different compiler working?

EDIT: One more edit hehe. I got the files to link in borland but I am still getting the same link errors!

FINAL EDIT: Haha and I said that the first two edits would be enough. I got my code to compile! It isn’t listed in the main setup instructions, but in the faq it mentions that you must #include the windows.h header file since the gl, glu, glut header files make use of it. I added the include and it compiled with no link errors!!

Thanks everyone so much for your help!

i fixed your code! check the private msg for the link

i compiled it by making a console application project