Jump to content
  • Advertisement
Sign in to follow this  
s33d

OpenGL Library linking with Eclipse CDT

This topic is 2302 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So I've got the SDK working and I'm trying to draw the basic triangle.

#include <gl/glut.h>
void drawSub(void){
//color, dimensions, type
glColor3f(0.0,0.0,0.0);
//vertex, dimensions, type
glVertex3f(-0.5,-0.5,-3.0);
glColor3f(1.0,0.0,0.0);
glVertex3f(0.5,-0.5,-3.0);
glColor3f(0.0,0.0,1.0);
glVertex3f(0.5,0.5,-3.0);
}
void sSimResh(int x, int y){
if (y == 0 || x == 0) return; //Nothing is visible then, so return
//Set a new projection matrix
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//Angle of view:40 degrees
//Near clipping plane distance: 0.5
//Far clipping plane distance: 20.0
gluPerspective(40.0,(GLdouble)x/(GLdouble)y,0.5,20.0);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,x,y); //Use the whole window for rendering
}
void sSimDisp(void){
//clear the color buffer
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
//start drawing stuff
glBegin(GL_POLYGON);
drawSub();
//close rendering stuff
glEnd();
glFlush();
}
int main(int argc, char **argv) {
//initialize GLUT
glutInit(&argc, argv);
//display mode: color index/RGB, 1x/2x buffering
glutInitDisplayMode(GLUT_RGB|GLUT_SINGLE);
//window size
glutInitWindowSize(300,400);
glutCreateWindow("Main Window");
//assign a clear color (R,G,B,alpha)
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
//required functions
glutDisplayFunc(sSimDisp);
glutReshapeFunc(sSimResh);
//let GLUT do things
glutMainLoop();
//loop forever
return 0;
}


All fine and good. In the linker section of the project, I have (under -l): glu32, user32, freeglut and opengl32. Eclipse doesn't tell me it's having any problems finding said libraries, so I assumed I was good to roll (includes checked out fine too). Despite this, i'm getting linker errors (undefined reference to `_imp__glutMainLoop@0' etc).

I know my choice of IDE is less than ideal, but I use it for everything else from Java to Python, so I really don't want to install another one, though I hear the whole OpenGL deal is much smoother on VS. I'm hoping it's something I'm doing wrong as opposed to the source code needing fixing like it did earlier when I tried to build the SDK...

Share this post


Link to post
Share on other sites
Advertisement
I'm fine with Eclipse... Without having ever used glut, I guess you probably need to link to -lglut and not freeglut?

Share this post


Link to post
Share on other sites
In general the use of glut is discouraged because it is unmaintained and old. freeglut is a reasonable alternative and should provide all the needed symbols. I'm not familiar enough with Eclipse and C++ to debug the issue, but it should work on principle.

Did you compile freeglut yourself or did you try the precompiled version?

Share this post


Link to post
Share on other sites

In general the use of glut is discouraged because it is unmaintained and old. freeglut is a reasonable alternative and should provide all the needed symbols. I'm not familiar enough with Eclipse and C++ to debug the issue, but it should work on principle.

Did you compile freeglut yourself or did you try the precompiled version?


Compiled it myself. I have a few tutorials that use it, so I know it works. They have all the libraries in a subfolder though...

Share this post


Link to post
Share on other sites
Do you get a different error if you rename/remove the freeglut library file? Also, is there any other output by the linker? Can you make the linker more verbose (i.e. to say exactly which libraries it is opening and which functions it is taking out of there)? I know MSVC has the /VERBOSE family of switches but I'm not sure about MinGW.

Share this post


Link to post
Share on other sites
i had issues with linking static libraries in eclipse as well. For me the issue was that the libraries i tried to link were not in a subfolder of the project's root (even output libraries from other projects also in the workspace could not be linked).

To fix this i just made a libs folder, pasted all the libraries in there and then linked them.

You may also have to take a look at the order in which you're linking the libraries. Not sure why but this was an issue for me as well, it may have something to do with something else though so try the other thing first.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!