VC++6: linking problems w/ new source file

Hi,

I’m learning some OpenGL on windows. I grabbed the only source file from a tutorial. There was a workspace/project for the tutorial but the source code is the really important thing. Now I made a new win32 app. workspace then added the source file to it. I compile fine. but building creates link errors.like so


prac.obj : error LNK2001: unresolved external symbol _gluPerspective@32
prac.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
prac.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4
prac.obj : error LNK2001: unresolved external symbol __imp__glViewport@16


The tutorial works fine when I compile/build it but this is having problems. I’m baffled . what could be different? Anyone have a hint?

thanx,

Hi !

I guess you have missed to include glu32.lib and opengl32.lib to your project.

Mikael

Try adding this to the top of your code:

#pragma comment (lib, “opengl32”);
#pragma comment (lib, “glu32”);
#pragma comment (lib, “glaux”);

These comments link the libraries to your code.

  • Halcyon

H,

Yes that worked. but I’m still not sure why it works fine when listed in the original project and not in the one I created. I was already loading

#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

which suffice for the original code.

thanx.

Sounds like your forgot to link the OpenGL libraries. Checl the Settings for your project and the example project.

Originally posted by Blaqb0x:
[b]Hi,

I’m learning some OpenGL on windows. I grabbed the only source file from a tutorial. There was a workspace/project for the tutorial but the source code is the really important thing. Now I made a new win32 app. workspace then added the source file to it. I compile fine. but building creates link errors.like so


prac.obj : error LNK2001: unresolved external symbol _gluPerspective@32
prac.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0
prac.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4
prac.obj : error LNK2001: unresolved external symbol __imp__glViewport@16


The tutorial works fine when I compile/build it but this is having problems. I’m baffled . what could be different? Anyone have a hint?

thanx,[/b]

The reason it worked on the origninal project is that the person who created it linked the libraries in their settings. You didn’t when you created yours. The #pragma lines i gave you did the linking for you. That’s the reason i use the #pragma lines…anyone who is looking at my code doesn’t have to worry about linking the libraries through the settings. Plus it sounds cool!

  • Halcyon

Edit: The #include statements dno’t load the libraries. They load the declarations and the header file. You need to link the library which holds the implementation of the declarations in the header files.

[This message has been edited by HalcyonBlaze (edited 02-25-2003).]

“The #pragma lines i gave you did the linking for you.”

Not very portable though, is it?