Skip to main content
GameDev.net gamedev.net
🔒 Locked

Linker Error.

Started by horizon981 Mar 14, 2006 at 10:00 AM 7 replies 6k views
Original Post
horizon981
horizon981
I'm using GLUT with Dev Cpp. I am having very strange problems. Although some programs work very well, others give me weird linker errors for same linker settings i.e. -lopengl32 -lglu32 -lglut32 Please help.
ToohrVyk
ToohrVyk
I am currently trying to guess what weird linker errors you encountered. Once I get that out of the way, I'll try to answer.
horizon981
horizon981
Well, here's the code:

//An animated square
#include
#include
#define GL_PI 3.14159f

GLfloat xRot=2.0f,yRot=5.0f;
GLfloat windowWidth,windowHeight;

void RenderScene(void)
{
GLfloat x,y,z,angle;
glClear(GL_COLOR_BUFFER_BIT);

glPushMatrix();
glRotatef(xRot,1.0f,0.0f,0.0f);
glRotatef(yRot,0.0f,1.0f,0.0f);

glBegin(GL_POINTS);
z=-50.0f;

for(angle=0.0f;angle<=(2.0f*GL_PI)*3.0f;angle+=0.1f)
{
x=50.0f*sin(angle);
y=50.0f*cos(angle);
glVertex3f(x,y,z);
z+=0.5f;
}
glEnd();

glPopMatrix();
glFlush();
}

void SetupRC(void)
{
glClearColor(0.0f,1.0f,0.0f,1.0f);
glColor3f(0.0f,1.0f,0.0f);
}

void ChangeSize(GLsizei w, GLsizei h)
{
if(h==0)
h=1;

glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

if(w<=h)
{
windowHeight = 250.0f*h/w;
windowWidth = 250.0f;
}
else
{
windowWidth = 250.0*w/h;
windowHeight = 250.0f;
}

glOrtho(0.0f,windowWidth,0.0f,windowHeight,1.0f,-1.0f);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}

int main(void)
{
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutCreateWindow("Spring");
glutFullScreen();
glutDisplayFunc(RenderScene);
glutReshapeFunc(ChangeSize);

SetupRC();
glutMainLoop();
return 0;
}

AND THE ERRORS:
[Linker error] undefined reference to glFinish@0'
[Linker error] undefined reference to
wglSwapBuffers@4'
[Linker error] undefined reference to wglSwapBuffers@4'
[Linker error] undefined reference to
wglGetCurrentContext@0'
[Linker error] undefined reference to `wglGetCurrentDC@0'
etc.

I'm going nuts... plz help me.
levjs
levjs
You need to link to opengl32.lib/glu32.lib/glaux.lib??

//Put at the top under your #include lines#pragma comment( lib, "opengl32.lib" )		// Search For OpenGL32.lib While Linking #pragma comment( lib, "glu32.lib" )			// Search For GLu32.lib While Linking    #pragma comment( lib, "glaux.lib" )			// Search For Glaux.lib While Linking


: ) Tell me if it works.

Levi
purple_moon
purple_moon
It seems that you've missed glaux.a. Pass it to your linker. If this doesn't work, try to update/reinstall MinGW.
Xeee
Xeee
don't forget that for mingw(the compiler used by DevCpp), the order of libraries MATTERS!
I think that the correct order is glut then glu then opengl, so the command line will be: -lglut32 -lglu32 -lopengl32 , but I'm not sure, so if this didn't work try all the different possibilities :) (3! = 6... not much)
xee..
purple_moon
purple_moon
Quote:
Original post by Xeee
don't forget that for mingw(the compiler used by DevCpp), the order of libraries MATTERS!
I think that the correct order is glut then glu then opengl, so the command line will be: -lglut32 -lglu32 -lopengl32 , but I'm not sure, so if this didn't work try all the different possibilities :) (3! = 6... not much)


Well, the order matters? I always use "gcc source.c -mwindows -lopengl32 -lglu32" (I haven't got into need of glut32 yet) to compile, and it works quite well.
Xeee
Xeee
yes, the order matter... I'm not sure what's the correct order, but I'm sure that the order matters, here's my proof
xee..
Falken42
Falken42
Quote:
Original post by Xeee
yes, the order matter... I'm not sure what's the correct order, but I'm sure that the order matters, here's my proof

Uh, yes, but that's only important if the object files and libraries passed actually contain the same named functions (ie: weak symbols). None of the OpenGL, glu32, or glut32 libraries contain conflicting function names at all, so the order does not matter in this case.

To the OP: If you've setup Dev-C++ to link to those OpenGL libraries properly, then you shouldn't have any problems. I've never used Dev-C++, so I'm afraid I won't be of much help... :(

Also, I'm pretty sure #pragma comment(lib, ...) is Microsoft specific. Could be wrong, though.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.