PDA

View Full Version : VC++6: linking problems w/ new source file



Blaqb0x
02-22-2003, 11:16 PM
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,

mikael_aronsson
02-23-2003, 12:30 AM
Hi !

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

Mikael

HalcyonBlaze
02-23-2003, 08:58 AM
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

Blaqb0x
02-24-2003, 07:42 AM
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.

02-24-2003, 09:16 AM
Sounds like your forgot to link the OpenGL libraries. Checl the Settings for your project and the example project.



Originally posted by Blaqb0x:
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,

HalcyonBlaze
02-25-2003, 06:52 AM
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).]

starman
02-25-2003, 08:23 AM
"The #pragma lines i gave you did the linking for you."

Not very portable though, is it?