Click to See Complete Forum and Search --> : OpenGL in Windows, small problem


Malone
06-20-2002, 09:47 PM
I'm pretty new at C++ for starters, and VERY new at Windows programming, but I got a book from the library about programming OpenGL apps in Windows. The book starts off with a very simple example: a Windows application that opens a window with an OpenGL rendering context, that has a simple red triangle rotating in the middle of the window. The code seems fairly straightforward, and I think I understand most of it.

Here's the catch though. I type in the code EXACTLY as I see it in this book into my trusty VC++ 6.0 editor in a new empty project. It is a single .cpp file. I then compile the code. It compiles fine, zero errors, zero warnings. But when I go to run the executable, it asks me if I want to build it (i choose yes of course), then it gives me the following error messages...

--------------------Configuration: MyFirstOpenGLApp - Win32 Debug--------------------
Linking...
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol _gluPerspective@32
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glViewport@16
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__wglCreateContext@4
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glEnd@0
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glVertex3f@12
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glBegin@4
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glColor3f@12
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glRotatef@16
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glTranslatef@12
BasicWindowsOpenGLApp.obj : error LNK2001: unresolved external symbol __imp__glClear@4
Debug/MyFirstOpenGLApp.exe : fatal error LNK1120: 14 unresolved externals

I really have no idea what these mean, and the book isn't any help on debugging issues. I realize it would help if I posted the entire program, but it's pretty lengthy. I'm just wondering if anybody here can tell me in general terms what these errors are?

stoo
06-21-2002, 07:43 AM
You probably haven't installed the OpenGL libraries for Visual Studio. The problem isn't with the code (if it compiles it is probably fine) but the linking: a required library is missing. IIRC, libraries should be specified under Project -> Project Settings -> Link.

Zoma
06-21-2002, 09:52 AM
Yeah, you probably need to add opengl32.lib and possibly glut.lib or glut32.lib. opengl32.lib should be in your VC++ folder under lib/gl. You will have to download glut32 if you need it. I think there is another .lib you may need, but I can't remember. There is probably only 2-3 .lib files in the /gl directory, so add the other one if it is there.

Zoma
06-21-2002, 09:53 AM
glu32.lib was the other library I was thinking of. Add it, as well.

Malone
06-21-2002, 11:59 PM
Wow, thanks a lot! That did it. I had to add opengl32.lib and glu32.lib in the settings. Thanks again.

Zoma
06-24-2002, 09:38 AM
No problem. BTW, anytime you see a link-time error, it is usually that you forgot to add or are missing a library. If you usually just compile and link together, all the '@' symbols, underscores, and words like "external symbol" are dead giveaways for a linker error.

Malone
06-28-2002, 12:14 AM
Good to know. That will save me a lot of headaches I'm sure.